- Home /
How to make a player change into other objects
Hello,
I've been doing unity for a long while now, but only the scripting part is still tricky. I am making a kind of a PropHunt game, and i need help with my JavaScript. I already have that when you click, you change into a object, but then you cant walk or move. i have seen alot of other unity forums and documents, but nothing helps. any help will be appreciated. thanks. My script:
var player : GameObject;
var Changer : GameObject;
var AnimObject : GameObject;
var Spawn_Position;
function OnMouseUp(){
Destroy(gameObject);
Instantiate(Changer,AnimObject.transform.position,AnimObject.transform.rotation);
}
function Update ()
{
if(OnMouseUp == true){
Instantiate(Changer,AnimObject.transform.position,AnimObject.transform.rotation);
}
}
I think you rather mean the mesh change http://answers.unity3d.com/questions/26894/how-do-change-the-mesh-of-a-game-object.html If you change the mesh - you still should be able to walk and move - provided it has the same animations you could still use and will ineract with other object in the same way.
Answer by Kiloblargh · Dec 15, 2013 at 09:54 PM
You're destroying the object with the script on it on mouse up. Any other scripts on that object will not work after that.
The code in Update() should not be there.
Variable names should be lowercase.
Here is the help with Javascript you need.
Now i have changed the mesh in my script. and deleted the Destroy(gameObject); line. But what now? when click on the block that i want to become, ( its a standard cube) it says that it could not instantiate. Its very weird, and thanks for all the help, but it doesn't work, and I really would like to go on with my game. anyway, thanks alot guys, and hopefully we will sort this out.
Answer by g0tNoodles · Dec 20, 2013 at 03:21 PM
You could change the mesh or have an empty parent object that has all the objects you wish to change in to as children. Depending on how you are planning on using the different objects you change in to (different skills for example), you could have a simple script that changes the player's form on the parent and then just make the other objects active or inactive.
No need to instantiate in my opinion, many people do something similar to the above. Easier just to turn some things on and off.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Can I Make A Game launcher Using Unity 0 Answers
Beast lighting like mirrors edge. 1 Answer
Collecting Papers and Keeping Track of how many collected - need help 1 Answer
FPSMouseScript.js 1 Answer