- Home /
Question by
haziqikhwan · May 27 at 11:36 AM ·
unity 2d
I have 2 collider but i only want one of them to interact with other things, this cause the coin collected sometimes detected as 2 coin because the are 2 collider
private void OnTriggerEnter2D(Collider2D other) {
if(other.gameObject.CompareTag("Coin"))
{
Destroy(other.gameObject);
} else if(other.gameObject.CompareTag("Obstacles"))
{
GetComponent<PlayerMovement>().enabled = false;
FindObjectOfType<GameManager>().GameOver();
} else if(other.gameObject.CompareTag("Objectives"))
{
objectives = objectives + 1;
Destroy(other.gameObject);
} else if(other.gameObject.CompareTag("wrongAnswer"))
{
objectives = objectives - 1;
Destroy(other.gameObject);
}
}
Comment