- Home /
problem whit Instantiate Prefabs position.
Hi everyone. I have a GameObject (which is a vehicle that moves in the scene). He has a child a gameobject. In that I put a trigger type collider box and a script. The script says that by colliding, I instantiate another vehicle (with other features and that is a PREFAB) while the original vehicle is destroyed:
public GameObject PrefabObject;
public GameObject destroyOriginalObject;
void OnTriggerEnter (Collider other)
{
if (other.gameObject.tag == "Player")
{
Instantiate(PrefabObject, transform.position, transform.rotation);
Destroy (destroyOriginalObject.gameObject);
}
}
This works but at the moment of Instantiate the new GameObject Prefabs, in the scene it is positioned very far from where the original GameObject is (destroyed). But the strange thing is that when I see the transform in the inspector it has effectively copied the same position and rotation but in the scene it is positioned elsewhere. How can I fix it? Thanks a lot!!!
Which object has the script that you posted? The parent or the child?
Your answer
Follow this Question
Related Questions
Why can't I instantiate an object that is +5 in the x and z axis? 1 Answer
Can't remove instantiated prefab 0 Answers
Destroying & Then Spawning Quickly 1 Answer
How do I duplicate an object to work with a shootemup 0 Answers
How to follow multiple clones positions of an instantiate prefab having a velocity ? 1 Answer