Question regarding transporting my character to new level using switch case

Hello. I have a question since I am new to unity. I created a simple scene level where I placed 4 cubes on the level and created a FPS character to move around. I used a pick-up script to allow my character to pick up the 4 cubes. My question is that I need help created a switch case script so that after collecting the 4 cubes I want text to appear on the screen saying something like “Congratulations! Proceed to next level” then after that I need a command to happen like character touching an object or pressing a button to be transported to a new scene level AFTER collecting the 4 cubes. Help would be appreciated. Thanks!

You do not need a switch case script in your case, an if loop will do. And i have made a simple script for you to take a look at. And button wise use GUI.Button and if you want to click on 3d objects instead. You can use function OnMouseDown() and OnMouseUp().

private var cubesCollected : int;
private var showWinText : boolean;

function Update()
{
    if (cubesCollected == 4)
    {
        showWinText = true;
    }
}

function OnGUI()
{
    
    if (showWinText)
    {
         GUI.Label(Rect(30, 30, 30, 30), "Congrats you win");
        if (GUI.Button(Rect(40, 40, 40, 40), "Click to continue"))
        {
            Application.LoadLevel(1);
        }
    }
}

function CollectCubes()
{
    // your function for collecting cubes here using trigger or whatsoever and update collected cubes to +1
    cubesCollected++;
}

Thanks. Where do I attach this script to? And where in the script shows where I can send my character to the next level (another unity scene I created)

The part where it transfer to next level.

function OnGUI() 
{          
    if (showWinText)    
    {          
        GUI.Label(Rect(30, 30, 30, 30), "Congrats you win");         
        if (GUI.Button(Rect(40, 40, 40, 40), "Click to continue"))         
        {             
            Application.LoadLevel(1);         
        }     
    } 
}

And this script is supposed to be attached to your character as you said that when your character picked up and i have a dummy function at the bottom called collect cubes which you must add some sort of picking up script then just call collect cubes.

I will give it a try, thanks. One more question, on my GUI script I have Health Points (HealthPos) and Points when collecting my cube objects (PointsPos) attached so that when my player hits something that damage then health points would go down 10 points. When health reaches 0, how can I make it say “GAME OVER” and then have the game start over again?

In the update loop currently it checks if it already have 4 cubes so likewise you can add a variable that is health and checks if is 0 then maybe in the OnGUI function bring up something that says you lose. :smile: