1

I have a controllable character that when you fall off map, a GUI will be created with a respawn button

        void OnGUI() {
        if(died==true){
        GUI.Label(new Rect(daX, daY, 200, 40), "You died!!");
        GUI.Label(new Rect(daX, daY-40, 200, 40), whyDie);
        if (GUI.Button(new Rect(daX-75, daY+50, 150, 30), "Respawn!!!")){
            transform.position = new Vector3(-5,20,5);
        }
        if (GUI.Button(new Rect(daX-75, daY+100, 150, 30), "Screw This!!!")){
            Debug.Log("Back to menu");
        }
    }
 }

The respawn and stuff works, is just that I don't know how to get rid of the GUI, so the respawn button stays there after you respawned. Does anyone know how to remove GUI objects? Thanks in advance

*EDIT: died, daX, daY, whyDie are variables I created and are valid

4

1 回答 1

2

Just set your died variable back to false, and the GUI calls wont be made.

void OnGUI()
{
   if(died)
   {
        GUI.Label(new Rect(daX, daY, 200, 40), "You died!!");
        GUI.Label(new Rect(daX, daY-40, 200, 40), whyDie);

        if (GUI.Button(new Rect(daX-75, daY+50, 150, 30), "Respawn!!!"))
        {
            transform.position = new Vector3(-5,20,5);
            died = false; //Stop drawing died interface
        }

        if (GUI.Button(new Rect(daX-75, daY+100, 150, 30), "Screw This!!!"))
        {
            Debug.Log("Back to menu");
            Application.LoadLevel(0); //Load your first scene, where the menu is.
        }
    }
 }

Alternatively, you could disable the component/gameobject. That way your whole OnGUI method wont be called anymore.

于 2012-05-29T14:28:44.420 回答