I have my player and it has a Box Collider 2D as “Is Trigger”.
I have a barrier where the player must jump to bypass. This barrier has a Box Collider 2D as “Is Trigger”.
When the player touches the barrier the following code is processed:
void OnTriggerEnter2D () {
Sound.PlayOneShot (SoundHurt);
Application.LoadLevel ( "gameover");
}
(So far, everything is working perfectly)
I added a coin and it has a Box Collider 2D as “Is Trigger” and the goal is when the player touches it, the coin short screen. The following code is processed:
void OnTriggerEnter2D (Collider2D Coins) {
Sound.PlayOneShot (SoundCoins);
if (Coins.gameObject.tag == "Coins") {
Destroy (Coins.gameObject);
}
}
void OnTriggerEnter2D () {
Sound.PlayOneShot (SoundHurt);
Application.LoadLevel ( "gameover");
}
Now only the first OnTriggerEnter2D is working.
I guess I should not have put both (barrier and coin) as “Is Trigger”, but I can not think of another way and make both work correctly, as I wish.
Can anybody help me?