- Home /
Duplicate Question : http://answers.unity3d.com/questions/638407/how-come-when-the-player-runs-into-the-coin-it-won.html
Why won't the coin destroy when hit?
The code works by a coin drops after you kill a monster, and if you run into the coin it's supose to be destroyed. The code works if you run into the coin within like a second of killing the monster but if you kill it, wait a couple seconds, then run into the coin it just stays there and doesn't disappear, anyone know why?
void OnTriggerEnter(Collider theTrigger){ if (theTrigger.gameObject.name == "Player"){ PlayerHitScript.coin_count += 1; Destroy(this.gameObject); } }
The code works by a coin drops after you kill a monster, and if you run into the coin it's supose to be destroyed. The code works if you run into the coin within like a second of killing the monster but if you kill it, wait a couple seconds, then run into the coin it just stays there and doesn't disappear, anyone know why?
Try changing Destroy(this.gameObject); to Destroy.gameObject;
Follow this Question
Related Questions
How come when the player runs into the coin it won't destroy? 1 Answer
Is there anyway to make an object impenetrable? 1 Answer
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
Destroy a specific object on trigger? 1 Answer
How do I call an on trigger enter / destroy gameObject in the scene c# 1 Answer