Collision with object not working.

I want to check if my player is touching an object that loads the next level.
Here is my code:

public class LoadNextLevel : MonoBehaviour {

    public string nextlevel = "e";

    void OnCollisionEnter(Collider target)
    {
        if (target.CompareTag("Player"))
        {
            SceneManager.LoadScene(nextlevel);
        }
    }
}

Collider is used for triggers. Collision is used for colliders. Why I am not really sure. It is really annoying that it doesn’t flag it as an error and simply doesn’t work if you forget to change it.

Change your code to this:

 public class LoadNextLevel : MonoBehaviour {
 
     public string nextlevel = "e";
 
     void OnCollisionEnter(Collision target)
     {
         if (target.CompareTag("Player"))
         {
             SceneManager.LoadScene(nextlevel);
         }
     }
 }

…and make sure that at least one of the colliders has a rigidbody on it and it will work.

Try this:

void OnCollisionEnter (Collision Colider)
	{
		if (Colider.gameObject.tag == "Player") {
			SceneManager.LoadScene("Town Outside");
		}
	}
}