I have this game i am working on. And i am having a Player prefab that is the one the user controlling. I have coins that i want the Player to collect them when he is passing by them.
using UnityEngine;
using System.Collections;
public class PickUpCoin : MonoBehaviour
{
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter2D(Collider2D other)
{
Debug.Log("collision name = " + other.gameObject.name);// i track if the collision values are correct.And they are.
if (other.gameObject.CompareTag("Player")) {
Destroy(gameObject);
}
}
}
The thing is that the Player tag is Player and when i am passing by it the debug correctly says that they actually collided. The coin has “Is Triggered” checked and also a circleColider2D. What basically i believe it’s happening is that my object is not destroyed. I am confused. I watched all the tutorials in the site that say about collecting coins and destroying the object. i cant trace the error here. I would greatly appreciate your suggestions. Thank you