- Home /
Tracking UI button presses
I intend to have 100+ buttons with the same script. The first of the 100 buttons I press needs to transform.parent to location1 and then move to the parent object's location and then the next of those 100 buttons needs to transform.parent to location2 so on and so on. How can a script be made to have different outcomes based on how many buttons have been pressed?
Answer by KISP · Jan 21, 2019 at 03:54 PM
Have a static int variable in your script that starts at 0. Increase that variable every time one of the buttons is pressed. Static variables maintain the same value across all instances of the script, so you can use a regular if statement to determine where the button should go.
Your answer

Follow this Question
Related Questions
Transform an object in other 2 Answers
Public script references in the Inspector 2 Answers
Save different game object's datas using the same script? 3 Answers
Error In Lives While Respawning 1 Answer