Hi there,
What I am trying to do is change the character model during the game. For example I want to switch between a rock and a tree when a collision occurs. Does anyone know an easy way of doing this?
Thanks.
private Vector3 vectorforobject;
public GameObject prefab;
void OnTriggerEnter(Collider c){
if(c.tag=="objtoreplace"){
vectorforobject = c.transform.position;
Instantiate(prefab, vectorforobject, Quaternion.identity);
Destroy(c.gameObject);
}
}
What is happening is when you collide with the tree, it creates another object in place. Then it destroys the original object.
Set the object you want to replace as Is Trigger, set the object to replace tag to “objtoreplace” and place this script on the player.
Edit - Replaced the script as it was not working.