Cycle through objects on mouse click
I wanted to be able to cycle through a loop of game objects on a mouse click.
For example, If there was a cube, when you'd click it it would be replaced by a sphere. Clicked again it would change to something else and eventually loop back around to the cube.
Can anyone point me in the right direction?
maybe you'll need sth. like a Game $$anonymous$$anager to handle this, just some raycast hit deter$$anonymous$$ation & gameobject.SetActive(true/false) thing, no big deal.
Answer by SaurabhStudio · May 17, 2017 at 07:17 AM
int noClick = 0;
public GameObject[] objList;
public void btnClick()
{
objList [noClick].SetActive (false);
noClick++;
if ((noClick) >= objList.Length)
{
noClick = 0;
}
objList [noClick].SetActive (true);
}
Drag object in objList gameObject.
And call this method when you click button
would you be able to explain a bit more?. Nothing i do seems to work. Sorry I'm fairly new to this.
Just drag object you wont to change when we click on button in objList [] in inspector.
Then create a button and call btnClick() method.
this code will disable current object and enable new one.
Thank you for the Help! sorry my $$anonymous$$d went blank.
Hey there! $$anonymous$$any thanks for sharing this script with us.
I am trying to create a configuration so that I can scroll through multiple lighting fixtures once I select a specific one inside a room.
I used your script and managed to make a list inside of which I added the multiple options I want to cycle through (see image 01)
However, I cannot really figure out what to do next in order to actually use this option...
Could you give me a hand with this one?
[apologies for the possible stupidity of the question, I am a total newbie and cannot really get even the basics]
Your answer
Follow this Question
Related Questions
List resulting in out of range 0 Answers
How to enabled a specific gameObject in array? 0 Answers
randomly activate one of many gameobjects ?? 4 Answers
how to check all elements in array 2 Answers