- Home /
How do you change a player's 3d model via a script?
Ello Ello Ello!
So I'm a student currently trying to think up what I could do for my next assignment. I was thinking of a game where the enemy is a grandma who wants to feed you and you have to dodge the food she throws at you. But thing is, how could I change the player's 3d model during gameplay?
Answer by speedything · Aug 10, 2012 at 02:45 PM
Build a heirachy of GameObjects so you have an empty player object at the top.
Then attach your scripts to the Player object (not the model). Something like this will make the model change.
public GameObject model1 = model1Prefab;
public GameObject model2 = model2Prefab;
private GameObject currentModel;
void Start()
{
currentModel = Instantiate(model1, transform.position, transform.rotation) as GameObject;
currentModel.transform.parent = transform;
}
public void ChangeModel()
{
if (currentModel == model1)
{
GameObject thisModel = Instantiate(model2, transform.position, transform.rotation) as GameeObject;
Destroy(currentModel);
thisModel.transform.parent = transform;
currentModel = thisModel;
}
else()
{
GameObject thisModel = Instantiate(model1, transform.position, transform.rotation) as GameeObject;
Destroy(currentModel);
thisModel.transform.parent = transform;
currentModel = thisModel;
}
}
Any changes you want to make to position or rotation, you should apply to the parent object - not the model object.
Your answer
![](https://koobas.hobune.stream/wayback/20220613075444im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
MMD How to export model and animations to Unity as 3rd person controller? 2 Answers
How to make a model to seems like it is rotating very fast with out rotating it fast 1 Answer
How to make the character change to another? 1 Answer
Imported model is not responding to script 1 Answer
Unity 3d model animation 0 Answers