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);
         }
     }
 }
 
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Zoogyburger · Mar 10, 2016 at 11:02 PM
Try this:
 void OnCollisionEnter (Collision Colider)
     {
         if (Colider.gameObject.tag == "Player") {
             SceneManager.LoadScene("Town Outside");
         }
     }
 }
Answer by Fredex8 · Mar 09, 2016 at 07:01 PM
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.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                