- Home /
Add Text To UI Panel on Button Click
Hello! I am extremely new to Unity.
My panel is called displayText. My Button is called Age Button.
Basically, I am trying to write a script that, if a button is clicked, the the text ["Age: " + age] will show in the displayText panel. The script is below:
Afterward, I added the script to the button, but it would not show the function. Do I need to do anything to the panel?
If you need more pictures, let me know!
Answer by 28mitu · Feb 26, 2020 at 11:40 PM
@shsearle13 I hope you dragged the "AgeButton" Game Object into "OnClick()" as I did in the attached screenshot. If you already did that then could you please share the screenshot of your Inspector window.
Thanks, Mitu
@28mitu Here is my inspector panel now. Hopefully this is what you wanted. How do I get it to show on the panel?
Hi, You need to drag the Age Button(button object which you will click) on OnClick() and the TextField which you wanted to show in DisplayText Field. Let me know if it helps.
Never$$anonymous$$d, got it to work. I needed to add a text field, which I didn't add.
How to I make the words appear not strectched and not blurry? I also want it to go like this:
"Age:1 Age: 2 Age: 3"
Like, one age per line?
Your answer
Follow this Question
Related Questions
Question on Tutorial: Panes, Panels, Windows 0 Answers
"Object reference not set to an instance of an object" after LoadScene 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers