I made a script to switch to a different scene once the animation ended. It worked once, but then I tried it again and it didn’t work!
Here’s the script I used:
using UnityEngine;
public class LVLENDTOMENU : MonoBehaviour {
public GameManager gameManager;
void Start ()
{
gameManager.QuitToMenu();
}
}
The game manager script (Which has worked before):
public void QuitToMenu()
{
SceneManager.LoadScene(“MainMenu”);
}
I simply had the script be disabled at the start of the cutscene and then enable at the end!
To my surprise this didn’t work twice. Please help, and maybe suggest a better method!
Maybe you used wrong scene name. Try this instead:
- Go to File > Build Setting, add the target scene (by pressing add open scene, obviously the scene must be currently opened), then check out the number (index) on the right.
- In your script, use “SceneManager.LoadScene(target_scene_index)” instead.
Keep in mind that you have to have “using UnityEngine.SceneManagement” at the script header.
I hope it works.
I tried this and got the same result as last time. Also, I didn’t expect this to work because if the scene name was wrong then an error would have appeared, but both times I saw no error! I think the script won’t enable, maybe something is blocking the script from activating??!?! Do u think?
Also: Here is the full game manager script:
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour {
public void DieW1 ()
{
Debug.Log(“!DEATHTYPE.1 = TRUE”);
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
public void LoadGameLVL01 ()
{
SceneManager.LoadScene(“LVL01P1”);
}
public void Reload ()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
public void CS02()
{
SceneManager.LoadScene(“LVL01CS02”);
}
public void LoadGameLVL02()
{
SceneManager.LoadScene(“LVL01P2”);
}
public void LoadGameLVL01CS01()
{a
SceneManager.LoadScene(“LVL01P1CS”);
}
public void QuitToMenu()
{
SceneManager.LoadScene(0);
}
public void LoadSelector ()
{
SceneManager.LoadScene(“CampaignSelect”);
}
}
Hm… Try printing a debug message before gameManager.QuitToMenu() and see if it’s called or not.
You can probably avoid using extra custom script tho, by calling gameManager.QuitToMenu() directly instead of enabling that script.