- Home /
 
transform code!
Is there a code in javascript or any other programing launguage in unity to transform one object into another for example
if my person (object 1) it within a distance of (lets say object 2) and you hit the button e you transform into object 2 destroying the original object of object 2(the one you were next to)
I would like the script so i could change my person into a car (therefor i would just have the car as a fps controler and you could drive around)
thx i know this is complicated but try and make sense of it
Answer by networkZombie · Mar 01, 2011 at 06:23 PM
This is how you do it in javascript-
var obj1 : Transform; //this is you var obj2 : Transform; // this is object2 var transformDist = 30;// this is the distance
 
               function Update(){
 
               if((distance >= Vector3.Distance(obj2.position, transform.position)) && (GetButtonDown("e"))) transform(); }
 
               function transform(){
 
               Destroy(gameObject); //destroys your player var replace = Instantiate(obj2, transform.position, transform.rotation); //this instantiates object 2 }
 
               //drag your player on the obj 1 slot and the car to obj2 slot //P.S. I haven't tested this script 
 
              Your answer
 
             Follow this Question
Related Questions
Turning Rigid body currently in contact with ground. 1 Answer
getting out of a vehicle 2 Answers
Gun Firing help? 2 Answers
How can i make the ray cast don't go through the walls 1 Answer
How do I make an enemy lead his shots? 2 Answers