Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by zuzia1992 · May 17, 2017 at 07:00 AM · arrayloopgameobjectssetactive

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?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Yuzuke · May 17, 2017 at 07:11 AM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image zuzia1992 · May 17, 2017 at 10:17 AM 0
Share

would you be able to explain a bit more?. Nothing i do seems to work. Sorry I'm fairly new to this.

avatar image SaurabhStudio zuzia1992 · May 17, 2017 at 10:54 AM 0
Share

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.

avatar image zuzia1992 SaurabhStudio · May 17, 2017 at 11:41 AM 0
Share

Thank you for the Help! sorry my $$anonymous$$d went blank.

avatar image AdamTegkelidis · Jan 23, 2019 at 02:51 PM 0
Share

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]

alt text

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

113 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

IndexOutOfRangeException: Index was outside the bounds of the array. (wrapper stelemref) System.Object.virt_stelemref_class(intptr,object) 1 Answer

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges