How to make a restart button pop up after character has died?
So I'm kind of new to this Canvas UI button and was wondering how to make a Restart button pop up after the character has died.
I already have a onclick script that restarts the level if it is pushed, but I don't know how to make the button not show up until the character has died.
Would it be somewhere along the lines of:
 (Button is invisible)
 
     if(dead)
     {
          //Make Button visible
     }
 
Answer by lloladin · Dec 24, 2015 at 12:48 AM
you could use SetActive and assign the button in the editor like this
      public gameObject RestartButton
         
         if(dead)
              {
                   RestartButton.SetActive(true);
              }
 else
 {
  RestartButton.SetActive(false);
 }
this should make the gameobject button visisble aslong as the object is dead and not visisble aslong as the object is alive
Answer by Harryliu · Dec 24, 2015 at 01:23 AM
Something like this will make the button invisible and disabled by setting the alpha value of the text and the button sprite to 0 - fully transparent, and by disabling the Button component to make it unclickable.
 #pragma strict
 import UnityEngine.UI;
 
 var restartButton : Button;
 var restartText : Text;
 var dead : boolean = false;
 
 function Start ()
 {
     restartButton.GetComponent(Image).color.a = 0.0;
     restartText.GetComponent(Text).color.a = 0.0;
     restartButton.GetComponent(Button).enabled = false;
 }
 
 function Update ()
 {
     if(dead == true)
     {
         restartButton.GetComponent(Button).enabled = true;
         restartButton.GetComponent(Image).color.a = 1;
         restartText.GetComponent(Text).color.a = 1;
 
     }
 
     else
     {
         restartButton.GetComponent(Button).enabled = false;
         restartButton.GetComponent(Image).color.a = 0;
         restartText.GetComponent(Text).color.a = 0;
     }
 }
hope it helps. although this might not be most convenient way, it's the only way I know.
Your answer
 
 
             Follow this Question
Related Questions
UI penetration through objects. 1 Answer
C# - Canvas UI addListener in code is not working 1 Answer
Use a canvas prefab multiple times at the same time 0 Answers
Player Can't Interact With UI 3 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                