Search
 
SCRIPT & CODE EXAMPLE
 

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;
         }
     
     }
 }
Comment

PREVIOUS NEXT
Code Example
Csharp :: C# one line method 
Csharp :: Match one of 1, 2, x or X, or nothing 
Csharp :: c# minimise form 
Csharp :: pubxml environment variables 
Csharp :: What are logic gates? 
Csharp :: monogame print 
Csharp :: null-conditional operators c# 
Csharp :: how to customize xunit input 
Csharp :: how to access path position variable in unity 
Csharp :: list array 
Csharp :: unity rigidbody freeze all rotation 
Csharp :: interop C# save as and replace 
Csharp :: unity line renderer opacity 
Csharp :: C# check if object is default 
Csharp :: if input.get touch 
Csharp :: Lambda Expression to filter a list of list of items 
Csharp :: button event trigger wpf 
Csharp :: c# convert excel column index to letter 
Csharp :: camera in raylib c# 
Csharp :: c# decimal 4 casas decimais 
Csharp :: c# get out of for loop 
Csharp :: ##[error]Dotnet command failed with non-zero exit code on the following projects 
Csharp :: c# async and await example 
Csharp :: C# Async Function with await 
Csharp :: c# generate random string 
Csharp :: HttpClient .net Core add Certificate 
Csharp :: instantiate object inside of object Unity 
Csharp :: *ngif vs ngif 
Csharp :: combined 2 arrays 
Csharp :: google mobile ads app id 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =