I have the script set up so when my player collides into the coin it should dissapear and be destroyed. (this code is attached to the coin)
void OnTriggerEnter(Collider myTrigger){
if (myTrigger.gameObject.name == "Player"){
Destroy(gameObject);
PlayerScript.coin_total += 1;
}
}
The coin is instantiated after a monster is killed in this code attached to the monster game object. Basically when it gets hit by a bullet he will be destroyed and drop a coin.
void OnTriggerEnter(Collider myTrigger){
if (myTrigger.gameObject.name == "Bullet(Clone)"){
Destroy(gameObject);
Instantiate(coin, transform.position, transform.rotation);
}
}
The monster gets destroyed and drops the coin just fine, but when the player collides with it, it doesn’t disappear or add to his coin count. I found that if a monster is colliding with the player while he’s colliding with the coin it works, but I don’t know why. I’m assuming it’s because I’m initiating the coin from the monster’s script. But if that’s the case I don’t know why my bullets work fine when they’re initiated from the Player’s script.