Hello everyone! Loads of times I have found very useful answerered questions, this time, my first time writing here, I need a little more help. I am sorry in advance for not being a pro with unity.
I would like some help on switching from scene to scene after an even happened in my game (I am using C# for my scripts).
So, I am making a “demo” videogame for a university project. I have made a Main Menu scene and a Game scene. This demo ends with entering a particular room with a Trigger Collider and when you hit this collider, a video starts playing.
My video player code is this one:
public GameObject videoPlayer;
public int timeToStop;
// Use this for initialization
void Start()
{
videoPlayer.SetActive(false);
}
// Update is called once per frame
void OnTriggerEnter(Collider player)
{
if (player.gameObject.tag == "Player")
{
videoPlayer.SetActive(true);
Destroy(videoPlayer, timeToStop);
}
}
}
then it destroyes the object and the game starts again from where I left.
I would like to completely change scene (so I would make a Game Over scene) or I would like to go back to my Main Menu.
I have a code that makes me switch between Main Menu and Game:
public void PlayGame()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
But this happens when I hit the Play button on the Main Menu. Now I would like to change scene suddenly after the event happened, so it won’t go through the game again.
Sorry for the long explanation and thank you even for reading this far!