Hello, I am making a game where a ball sprite that is bouncing around must detect if it’s colliding with the player. It works perfectly fine. This is the code I am using:
void OnCollisionEnter2D(Collision2D coll) {
if (coll.gameObject.tag == "Player") {
Debug.Log ("HIT");
GameObject.Find("gameFloor").GetComponent<playerTouchScript>().gameEnd = true;
Time.timeScale = 0.0f;
}
}
But when I place a very similar piece of code into another script on another sprite (or even the same script) it does not detect collision with the player. This is a snippet from an objective the player must collide with to get a bonus. It will not even detect a proper collision with my player, but it will with other balls bouncing around.
void OnCollisionEnter2D(Collision2D coll){
if (coll.gameObject.tag == "Player") {
GameObject.Find("Main Camera").GetComponent<gameManager>().score += 5;
Destroy(gameObject);
}
}
I am wondering if anyone has encountered anything like this? Any help is appreciated.