Hi all,
In a level of a game I’m currently making, the player (which is a prefab object) has to collect coins (prefabs also). The script I’m trying to get working will ideally destroy the coin on collision. Basic enough.
However, the current code I’m using will (when altered) destroy the player on impact, but not the coin (when I change it back to read ‘Coin’ instead of ‘Player’; this was merely to see if it was working).
Anyone know why the devil this’d be happening? I can’t find out, no matter what boxes I tick/untick… it just won’t work. Is it a double prefab thing?
Thanks again, any suggestions welcome.
using UnityEngine;
using System.Collections;
public class AsteroidCollision : MonoBehaviour
{
void OnCollisionEnter(Collision other)
{
if(other.gameObject.name == "Coin")
{
Debug.Log("Congratulations - You Collected 1 / 10 Coins!");
Destroy(other.gameObject);
}
}
}