Search Unity

Respawn menu script?

Discussion in 'Scripting' started by ecloev, Oct 6, 2015.

  1. ecloev

    ecloev

    Joined:
    Oct 1, 2015
    Posts:
    101
    Deos anyone have a RespawnMenu script?
    All i want is so when I die is that gui buttons will pop up saying return to menu and respawn.
    I am an ok coder so i can probably edit i just don't know where to start.
    Does someone have a sample i can use and tweak in C#?
    I would still like scene view to be enabled i just want ti so the camera and movement gets locked :)

    Thanks :)
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    make a canvas, with the two buttons. Configure the two buttons to do what you want.

    In your game manager script (whatever runs the game and keeps track of the playing/gameover states) create a canvas variable and drag the canvas into the slot in the inspector. In the GameManager script's start function disable the canvas. When the player loses and you enter the gameover state, enable the canvas.

    If you're not keeping a track of the "state" of your game (playing, gameover, menu etc.) you should probably start there instead...
     
  3. ecloev

    ecloev

    Joined:
    Oct 1, 2015
    Posts:
    101
    Yeah, i am not keeping track of it, can you give me a basis to start with? Well the game state part :)
     
  4. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Just have a bool if you want to keep it simple e.g. playerDead = false at the start & when they die change it to playerDead = true
    Have an if statement in your manager script that says if(playerDead){insert your code here for what you want to happen e.g. Activate your buttons }

    Make sure when they click the button to restart that you reset anything you were keeping track of like scores etc if you need to.
     
  5. ecloev

    ecloev

    Joined:
    Oct 1, 2015
    Posts:
    101
    Where would this go?
     
  6. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Not knowing exactly how you are doing everything I will answer based on my own stuff.

    Things that determine multiple stuff that aren't specific to one object I tend to put into the manager script, so that's where I'd put it. This is just because I would probably also use the bool to determine when timers start/stop, enemies can move, the player can move, backgrounds scroll or update, menus &/or buttons &/or text displayed etc

    Each of the relevant object scripts would access the bool from the manager script.