Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

Unity Pickable Object C# Script

Posted on January 29, 2021January 29, 2021 by Habibie

I was making a simple script for picking and putting down an object by getting close to a pick up and drop zone area in a game.

In this game my player object is a pick up car. And I tried to make a sphere as pickable object.

In both this videos you will see how I do it:

And here is the script used in these videos, I call it PickableObject.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PickableObject : MonoBehaviour
{
	
	public GameObject PickUpCarBack;
	
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
	
	private void OnTriggerEnter(Collider col){
		if(col.gameObject.name == "PickUpCarSensor"){
			transform.position = PickUpCarBack.transform.position;
			transform.parent = PickUpCarBack.transform;
		}
		
		if(col.gameObject.name == "DropZone"){
			GameObject DropPoint = col.gameObject.transform.Find("DropPoint").gameObject;
			transform.position = DropPoint.transform.position;
			transform.parent = DropPoint.transform;
		}
		
		
	}
	
	
	
}
Post Views: 336
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
  • Advanced Blinking Marker Script to show objects position in your game canvas
  • Ciihuy Images Merger – Fast & Easy Online Image Combiner
© 2025 ThirteeNov | Powered by Superbs Personal Blog theme