Trying to invoke method : CollisionHandler.Loadnextlevel couldn't be called

this error is since the previous lecture when I land on the landing pad it stays there and the next level won’t load. Help please I’m completely new to unity.

Hi Youssef,

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture? Maybe there is a typo in your code.

I did, everything is written as it should, nothing changed

Could you please share your code as formatted text?


See also:

using System;

using UnityEngine;

using UnityEngine.SceneManagement;

public class CollisionHandler : MonoBehaviour

{

[SerializeField] float levelLoadDelay = 2f;

[SerializeField] AudioClip succes;

[SerializeField] AudioClip crash;

AudioSource audioSource;

void Start()

{

    audioSource = GetComponent<AudioSource>();

}

 void OnCollisionEnter(Collision other)

 {

     switch (other.gameObject.tag)

     {

         case "Friendly":

             Debug.Log("This thing is friendly");

             break;

         case "Finish":

             StartSuccessSequence();

             break;  

          default:

             StartCrashSequence();

             break;              

     }    

 }

 void StartSuccessSequence()

 {

     audioSource.PlayOneShot(succes);

     // todo add particle effect upon success

      GetComponent<Movement>().enabled = false;

      Invoke("LoadNextLevel)", levelLoadDelay);

 }

 void StartCrashSequence()

 {

     audioSource.PlayOneShot(crash);

     // todo add particle effect upon crash

     GetComponent<Movement>().enabled = false;

     Invoke("ReloadLevel)", levelLoadDelay);

 }

 void LoadNextLevel()

 {

     int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;

     int nextSceneIndex = currentSceneIndex + 1;

     if (nextSceneIndex == SceneManager.sceneCountInBuildSettings)

     {

         nextSceneIndex = 0;

     }  

     SceneManager.LoadScene(nextSceneIndex);

 }

 void ReloadLevel()

 {

      int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;

      SceneManager.LoadScene(currentSceneIndex);

 }  

}

Your code looks fine. Have you already tried to restart Unity and your script editor? Maybe the script was not saved properly.

For example, the error message mentions Loadnextlevel but there is no such method of that name in your script. Only LoadNextLevel. C# is case-sensitive. Try to figure out where “Loadnextlevel” is.

sorry, it’s LoadNextLevel. problem not solved yet :thinking:

I’ve tried everything i know, nothing changed always LoadNextLevel couldn’t be called even I’m in the Second Level.

I think I found the issue. There is a typo, and it is so obvious that I completely missed it.

"LoadNextLevel)" → Remove the ) from the string.


See also:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms