Search Unity

Need HELP making sure that my LoseScreen 2 loads if player hits enemy on Level2

Discussion in 'Scripting' started by manilamerc, Mar 23, 2013.

  1. manilamerc

    manilamerc

    Joined:
    Oct 4, 2012
    Posts:
    102
    So here is a little code that I have. It makes sure if the character hits the Cube it will load the Lose Screen.
    On the Load Screen it has a button called Back which directs the player back to the Title Screen
    Code (csharp):
    1.  if (c.gameObject.name == "Cube" )
    2.     {
    3.      
    4.         Application.LoadLevel("LoseScreen");
    5.         audio.Play();
    6.     }
    7.  
    Thing is... I have another LoseScreen for level2 called LoseScreen2. On that LoseScreen it will have a Back button AND a button called Load Checkpoint. The Code above works for Level 1 and 2. The same Cube is on level 1 and 2. What I want is if the player hits the cube on Level 2 Load LoseScreen2.

    If Player hits cube on Level1 --> LoseScreen
    If Player hits cube on Level2 --> LoseScreen2
     
  2. chelnok

    chelnok

    Joined:
    Jul 2, 2012
    Posts:
    680
  3. manilamerc

    manilamerc

    Joined:
    Oct 4, 2012
    Posts:
    102
    could you write an example? I can't find any good ones
     
  4. EliteMossy

    EliteMossy

    Joined:
    Dec 2, 2012
    Posts:
    513
    Hmm have you even tried? Something like this should be simple to even someone new.

    A simple way would be to store a variable in the script with the scene to load, which you could modify in the inspector for each scene, like

    public string SceneToLoadWhenGameOver;

    then Application.LoadLevel(SceneToLoadWhenGameOver);

    This would be the simplest way but not the way i would do it.
     
    Last edited: Mar 24, 2013
  5. manilamerc

    manilamerc

    Joined:
    Oct 4, 2012
    Posts:
    102
    heres and idea I was thinking....

    Code (csharp):
    1.       if (c.gameObject.name == "Cube2"  currentlevel = Level2 )
    2.     {
    3.      
    4.         Application.LoadLevel("LoseScreen2");
    5.        
    6.  
    7.         audio.Play();
    8.     }
    but I'm not even sure if that's possible, or makes sense. I'm just trying random stuff
     
    Last edited: Mar 24, 2013
  6. EliteMossy

    EliteMossy

    Joined:
    Dec 2, 2012
    Posts:
    513
    I just gave you a soloution, you could do

    Code (csharp):
    1.  
    2.   if (c.gameObject.name == "Cube2"  Application.loadedLevelName = "Level2" )
    3.     {
    4.  
    5.         Application.LoadLevel("LoseScreen2");
    6.  
    7.         audio.Play();
    8.     }
    9.