Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

unity pickup and drop objects

I have no javascript version, but you can use something very simple like this in C#:

TakeMe.cs:

 using UnityEngine;
 using System.Collections;
 
 public class TakeMe : MonoBehaviour {
     
     private Transform taker;
     
     // Use this for initialization
     void Start () {
         
     }
     
     // Update is called once per frame
     void Update () {
             
         if(Input.GetKeyDown("t")) {
 
             transform.parent = taker;
             
         } else if(Input.GetKeyDown("g")) {
 
             transform.parent = null;
             
         }
 
     }
     
     void OnTriggerEnter (Collider col) {
         
         if(col.CompareTag("Player")) {
             
             taker = col.transform;
 
         }
         
     }    
         
     void OnTriggerExit (Collider col) {
 
         if(col.CompareTag("Player")) {
             taker = null;
         }
     
     }
 }
 
PREVIOUS NEXT
Tagged: #unity #pickup #drop #objects
ADD COMMENT
Topic
Name
9+5 =