Hiding GUI.Button after clicking the button (JS)
I'm trying to set up a respawn menu that you can press to bring back your character to the spawn point with full health when this button is pressed. How do I hide the buttons after they are pressed?
Code:
ar respawnTransform : Transform;
private var playerIsDead = false; var lookAround01 : MouseLook; var lookAround02 : MouseLook; var charController : CharacterController;
function OnGUI () { if (playerIsDead == true) {
if (GUI.Button(Rect(Screen.width*0.5-50, 200-20, 100, 40), "Respawn"))
{
RespawnPlayer();
playerIsDead = false;
}
if (GUI.Button(Rect(Screen.width*0.5-150, 240, 300, 340), "YOU ARE DEAD"))
{
Debug.Log("YOU ARE DEAD");
}
}
}
function RespawnPlayer () { transform.position = respawnTransform.position; transform.rotation = respawnTransform.rotation; gameObject.SendMessage("RespawnStats"); lookAround01.enabled = true; lookAround02.enabled = true; charController.enabled = true; Debug.Log("Player has respawned"); }
Answer by Gamesearch · Apr 07, 2016 at 07:09 PM
Like this?
var respawnTransform : Transform;
var playerIsDead; /*var lookAround01 : MouseLook; var lookAround02 : MouseLook; var charController : CharacterController;*/
function Start()
{
playerIsDead = true;
}
function OnGUI () { if (playerIsDead == true) {
if (GUI.Button(Rect(Screen.width*0.5-50, 200-20, 100, 40), "Respawn"))
{
//RespawnPlayer();
playerIsDead = false;
}
if (GUI.Button(Rect(Screen.width*0.5-150, 240, 300, 340), "YOU ARE DEAD"))
{
Debug.Log("YOU ARE DEAD");
playerIsDead = false;
}
}
}
/*function RespawnPlayer () { transform.position = respawnTransform.position; transform.rotation = respawnTransform.rotation; gameObject.SendMessage("RespawnStats"); lookAround01.enabled = true; lookAround02.enabled = true; charController.enabled = true; Debug.Log("Player has respawned"); */}
Your answer
![](https://koobas.hobune.stream/wayback/20220612074351im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Problem with making a tower select GUI 1 Answer
Touchscreen GUI Button Not Working With Mouselock 0 Answers
gui button textured how to 1 Answer
GUI Button Moving with a mouse 0 Answers
Why isn't WaitForSeconds working? 1 Answer