OnTriggerEnter not working, tried everything! :( (C#)

Hi, I’ve only spent a week using Unity so far so very new! Trying to make an arcade-style falling game within a tunnel. I can’t get this to work, despite having used this before successfully.

void OnTriggerEnter(Collider other)
	{
		print("YAY!");
		if(other.gameObject.tag == "Finish" && finished == false){
			
			if(terminal == true){
				win_text.text = "YOU WIN!";
			} else {
				lose_text.text = "YOU LOSE...";
			}
			finished = true;
		} else if (other.gameObject.tag == "Obstacle"){
			// can add response to collision with obstacles.
		}
	}

To my disappointment, the phrase “YAY!” is never printed, and there is no interaction with the various GUIText elements.

As you can see, I tried fixing it by having the GUIText not constantly refresh (it finishes with constant contact) by adding an extra boolean, but it wasn’t even being run in the first place.

The player (sphere, Sphere Collider) has this script attached to it, and the finish (cube, Box Collider) has the tag “Finish”. The player has a Rigidbody, the finish doesn’t.

I’ve been stuck on this for hours now and looking at similar posts I can’t resolve the problem. Please help!

For your objects to receive the OnTriggerEnter, at least one of them has to have the Is Trigger property checked and at least one of them has to have a Rigid Body. If neither of your objects is a Trigger, you can use OnCollisionEnter instead.

Once that’s all set, you should check the Layers (not Tags) on your objects. To edit which Layers collide with each other, you can look at Edit → Project Settings → Physics.

By default Unity sets all layers to collide with all layers. That’s a good works-by-default setup, but you may want to play with it to optimize later on.

Hi in 5.3.4 both objects need to have rigid body

Thanks for the response, it’s really helped me understand this better, but I found the issue… I was using the wrong function! I should have used onCollisionEnter all along, but thanks for the advice!