Change from second level to the next one
Hi, I'm very new to Unity and have a task to make a Roll-a-Ball game with 3 levels, but I can't go past the second one.
void SetCountText ()
{
countText.text = "Count: " + count.ToString ();
if (count >= 10)
{
WinText.text = ("You Win! Hooray!");
Application.LoadLevel("MiniGamel");
}
The code here shows that after the player has collected the required number of items and the win text appears on the screen, the player moves to the next level. But I don't know how to send a player to the third level after completing the second level.
{
if (count >= 15)
{
WinText.text = ("You Win! Hooray!");
Application.LoadLevel("MiniGamel2");
}
I tried to increase the number of items on the second level so that after the player moved to it, this number of items would carry them to the third level, but as soon as I collect 10 items, the second level starts over, not allowing me to pick up the rest of the items.
What could solve my problem?
Answer by Hellium · Aug 17, 2020 at 08:16 AM
1. Declare a public integer and a public string in this script called requiredPoints
& nextLevelName
respectively
2. In your SetCountText
, replace your current code by:
void SetCountText ()
{
countText.text = "Count: " + count.ToString ();
if (count >= requiredPoints)
{
WinText.text = ("You Win! Hooray!");
Application.LoadLevel(nextLevelName);
}
}
3. In the inspector of the player, in your first scene, set requiredPoints
to 10
and nextLevelName
to MiniGamel
4. In the inspector of the player, in your SECOND scene, set requiredPoints
to 15
and nextLevelName
to MiniGamel2