onClick Event for UI Text?
Hi, What am I doing wrong? I am trying to get when I click a button (EasterEgg hidden in the game) That is shows text on screen but I can seem to figure it out.
IMAGE:
Thanks!
Fixed it. It's bool show() but how do I make it when you click it Shows CLIC$$anonymous$$ AGAIN Clear CLIC$$anonymous$$ AGAIN Show ??
Answer by $$anonymous$$ · Feb 19, 2017 at 08:50 AM
Not sure if you've answered your question already, but to make it show or hide every time you click, you could do the following.
Have whatever text you want in the text object already written, then add a script that looks something like this to the button object:
public class TextShowHide : MonoBehaviour {
public void ShowHideText (UnityEngine.UI.Text text){
text.gameObject.active = !text.gameObject.active;
}
}
If you do this, you can then go to the button's onClick and choose the the button. Then for the method go to TextShowHide > TextShowHide (Text) and put whatever text object you want this to affect into the field.
When you click the button the text should then show when it's hidden and hide it when it's shown.
I hope this helped.
text.gameObject.active is obsolete to gameObject.SetActive or gameObject.selfActive
Your answer
Follow this Question
Related Questions
button.onClick.AddListener in for loop 2 Answers
Unable to assign callbacks in "Event Trigger" component in the inspector 2 Answers
Image Colour change not working with anythign other than base preset colours 2 Answers
adjust image size with mouse 0 Answers
Cant access variables outside of On Click() function 1 Answer