Trying to change level when player comes in contact with a platform.

So, I’m making a game for a school project. I’m using the base 2D asset robot character with a different art on it, and I’m trying to set it up so that when my character walks onto a platform then the level will change. The platform has a Box Collider on it already.

using UnityEngine;

namespace UnitySampleAssets._2D
	public class LevelChanger : MonoBehaviour
		private void OnTriggerEnter2D(Rigidbody2D other)
			if (other.tag == "Player")
				Debug.Log ("Working!");

This is the code I’ve been working with. I’ve checked that the Player tag was correct and all.

Any ideas as to what the issue may be?

As your are working with 2D, it is:

private void OnTriggerEnter2D(Collider2D other)

And your file name has to be the same as your class name


The argument for OnTriggerEnter is Collider, not Rigidbody2d. As you have it above, you are creating a function with a new signature that compiles fine, but does not get called by Unity for collision events. In summary, change to:

void OnTriggerEnter(Collider other)

Good luck!

Edit: also, make sure that it is truly the tag that is set to player, not the object name.