- Home /
how can i access multiple sprites using a single variable?
how can i access multiple sprites on the canvas using a single variable and perform action on them.
Answer by OneCept-Games · Jan 04, 2018 at 12:50 PM
Please be more detailed. What exactly is it you want to achieve?
You can create a Script with an Array or List of Sprite objects, add them all to the array and in your script access them one by one in the Update() or any other callback method.
Actually there are multiple sprites present on the UI canvas(like each individual sprite for each button) , and what I want is to dynamically allocate the sprite to a single variable for accessing it. Allocation should be done when a button is clicked on which that sprite is present.It should first check that on the clicked button , is there sprite present or not and if present then dynamically allocate it to a variable for accessing it.
Thank you for concern!!!
ok, I still don't quite get it, but you can always create a Script with a Public Variable called ie. selectedSprite, and then the OnClick of your buttons, call the same Function in the same script and assign the Sprite game object to your selectedSprite variable.