Tag Reading

Hi Folks,

I’m an absolute Noob, so forgive me in advance for this silly question…

I’m building a small 2D interactive application for my students.
I have 43 UI Buttons (name: keyBtn(a)…(b) etc.) belonging to Canvas.
Each of them has its own tag (A…B…C…) representing letters, numbers and special keys. I have a 2D Text (name: scratchPad) which shall show the final result of the clicked buttons.

  1. How to “read” the tag of each of the buttons when I click one of them; in Unity Manual and Script I am not able to find the correct routine to read a tag… I know I am a superNoob… the GetComponent doesn’t work at all for me…

  2. I want to store the tag into a string (ok, that’s superSimple) and

  3. add this string to the UI Text scratchPad and show it on the screen; practically, to “pass” the string.

Thanks for the help

When you press a button, pass it’s transform to a function. Then in a function you can use something like passedTransform.tag to read the tag. You can store it in a variable.

To show the tag on a text, have a variable which points to UI.Text type. Just set the string to thatTextvariable.text and you will be good to go.