- Home /
Why does my instatiate crashes editor?
After enetering the any weapon trigger editor crashes(it's becasue weapon kind which we have triggered is spawning all time, but i don't know why, because insattiate isn't inside Update method) What's wrong with my code? https://gist.github.com/kubawich/06821c43db2c8b0594810d03453a216b
You could simply do this :
Instantiate (weaponObject, HandPosition.position, Quaternion.identity);
HandPosition is already a Transform, no need to get its transform property, and position is already a Vector3, no need to build a new one.
What's the point of instantiating an object you destroy just before ? Can't you simply move it at the desired position ?
Answer by UnityCoach · Mar 25, 2017 at 05:58 PM
You pass it the reference to the object you just destroyed. Try this :
private void OnTriggerEnter(Collider other)
{
SetWeapon(other.gameObject);
GameObject.Destroy(other.gameObject); // delete other game object after instantiating
hasWeapon = true;
}
It doesn't work, because it keeps insatiating gun for infinity :/
OnTriggerEnter is only called once per trigger collider the object enters. You should check that it's only called once, by adding a Debug.Log ("trigger");
to OnTriggerEnter ().
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
My prefab isn't getting destroyed 1 Answer
How can I add the OnTriggerEnter function to all game objects that I instantiate? 1 Answer
Multiple Cars not working 1 Answer
Instantiate Side Affects 1 Answer