Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by excalith · Jun 27, 2015 at 12:14 AM · uiarrayslidertogglelogic

(Logic) Switch GameObjects With Slider Using Arrays

Hello, I am working on a school project which I am planning to show it on an Android tablet with touch input & gestures. And I am stuck at the very beginning.

Lets say I have 5 flats in a building on top of each other, named Flat0 to Flat4. I want to cycle through them with user input using Slider (any other idea is welcome!)

If slider value is 4(top value), it will show top flat with others active. If below 4, it will hide above current slider value.

So far I managed to hide and show game objects using arrays, but they don't work as they should. It seems like one of the lists start from 1 to 5 and my arrays work 0 to 4, for sure. Yet, I couldn't find the problem.

Thanks so much for the help!

Here is the code I managed to do so far:

 function sliderChange(){
 //Slider Gets the current slider value
     var Slider : UnityEngine.UI.Slider = GameObject.Find("slider").GetComponent(UnityEngine.UI.Slider);
     var currentSliderValue = Slider.value;
 
 //Slider Text: Writes the flat number to UI Text
     var SliderText : UI.Text = GameObject.Find("sliderText").GetComponent(UI.Text);
     SliderText.text = "Flat: " + currentSliderValue;
 


     var flatNumber = GameObject.FindGameObjectsWithTag("Flat") as GameObject[];
 
 //On slider change displays the first state
     Debug.LogError("Current Slider Value: " + currentSliderValue + " Flat Number: " + flatNumber.length);
 
 //HIDE
   var j = currentSliderValue;
   while(flatNumber.length > j){
     flatNumber[j].GetComponent(MeshRenderer).enabled = false;
     Debug.LogWarning("Hide: " + j);
     j++;
   }
 
 
 //SHOW
   var k = currentSliderValue;
   while(0 <= k){
     flatNumber[k].GetComponent(MeshRenderer).enabled = true;
     Debug.Log("Show: " + k);
     k--;
   }
 }

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 excalith · Jun 27, 2015 at 10:40 AM 0
Share

Okay, I reimported the meshes one by one. I was afraid of the script getting array in a random order. This time everything changed, still won't work but it seems I need to order arrays alphabetically. Is this the problem? Or why it gets elements randomly?

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

4.6 UI "Slider" jumps on handle press? 2 Answers

Why is UI Slider not working while Animator is enabled? 1 Answer

Changing Volume with Slider - not working with Unity2017.3 anymore? 1 Answer

TOGGLE UI problem 3 Answers

How to Find the Sum of each Individual item / array out of range 0 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