- Home /
Hiding "Next level" button if not finished
Hello!
I've tried hiding (or showing after finish) a next level button. I was able to do it when I created one in the script, but I'd like to do a physical button on the canvas.
How do I hide the button if finished = false?
Answer by Mmmpies · Jan 15, 2015 at 11:28 AM
Using the new 4.6 UI?
If so add a Canvas Group to it and you can alter the Alpha from 1 to 0 to hide the button, also Unclick BlockRaycast and Interactible so the button doesn't block mouse clicks in your game.
You can also gently reduce the alpha of a canvas group to fade out the button.
If the button is the only thing on the canvas then you should really base the canvasGroup on the actual canvas but you can also fade in and out individual elements by putting a canvas group on them.
EDIT:
Hold a reference to the button so:
using UnityEngine.UI;
...
public Button FinishButton;
// then set the various stuff on the canvas group
FinishButton.GetComponent<CanvasGroup>().alpha = 0; // or 1 to show
FinishButton.GetComponent<CanvasGroup>().interactable(false);
Sorry for any typos as I don't have access to unity, if you just want a quick method you can just set the button's active to false ...
FinishButton.SetActive(false);
Which is quicker but you can't do fancy fade in or out. As with the Alpha above being set to 1 to show it, set all the false values to true when you enable the button again.
Thank you, but how do I then make it visible when finished = true?
Otherwise a great answer.
Thank you! This is what I was looking for!. Unfortunately I can't upvote this answer :(.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
hide button 1 Answer
Distribute terrain in zones 3 Answers
How do I make a function not appear on UnityEvents / Button OnClick lists? 0 Answers