unity3d - C# OnTriggerEnter, Pick up an object. OnTriggerExit, drop the object -


i'm trying sprite pick cube when encounters one, if isn't carrying one. if is, drop cube carrying.

this have right now.

void ontriggerenter(collider other) {           if (other.tag == "cube")       {         other.transform.position = this.transform.position;     } } 

i tried telling cube become child of sprite. wasn't working. put cube sprites position when trigger entered, cube stays in position while sprite wonders off.

with code,you can change cubes position players position 1 time.if want cube move character should make child of character.

try using code;

void ontriggerenter(collider other) {           if (other.tag == "cube")       {         other.transform.parent = gameobject.transform;     } } 

ps:i don't have access unity now.some coding mistakes can occur.


Comments

Popular posts from this blog

java - unable show chart in xls document using jasper reports -

java.lang.RuntimeException: Could not generate dummy secret at sun.security.ssl.RSAClientKeyExchange.<init> -

javascript - How to change image src on success AJAX -