- Home /
Question by
Ajay2008 · Jul 10, 2020 at 11:10 AM ·
c#errorerror messageinvoke
Unity was not able to run my Invoke command, and im not sure why.
public void LoadNextLevel () { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
public void CompleteLevel ()
{ Invoke("LoadNextLevel()", 2); completeLevelUI.SetActive(true);
}
Comment
Trying to Invoke method: Game$$anonymous$$anager.LoadNextLevel() couldn't be called.
Didn't work same error message, thanks for your help though.
Sorry.. need to double check.. so you tried wirhout the ()?
Best Answer
Answer by finnjwohner · Jul 10, 2020 at 12:23 PM
First off double check you're using the UnityEngine.SceneManagement namespace.
Next, when you call Invoke(), you don't need the brackets after LoadNextLevel, so it should just be,
public void CompleteLevel() {
Invoke("LoadNextLevel", 2.0f);
completeLevelUI.SetActive(true);
}
Also, is CompleteLevel() in the same script as LoadNextLevel() ? If not, Invoke() won't be able to find it.