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 TrewSx · May 30, 2013 at 10:28 AM · javascriptslidergui.window

How to shift GUI.Buttons while clicking on a slider

Hello there,

i've asked this before with no reply so i will rephrase my question with a bit of code as well.

So lets say i have a GUI.Box and inside this Box is 20 GUI.Buttons. On left and right side i have a GUI.RepeatButton and when i click on right button it will scroll my track selection to the right, obviously the same goes for the left button just to the left side. It's like having my tracks in a loop so i could circle around. I am not very good with words so i hope you understand what i am trying to do.

 #pragma strict
 
 var icon    : Texture2D;
  
 private var _selectionWindowRect    : Rect  = new Rect(150,150,560,445);
 private var _selectionWindowID         : int   = 0;
 
 
 var hSliderValue : float = 0.0;
 
 function OnGUI () {
     
     // GUI.Button(Rect(Screen.width/2 - x,Screen.height/2 - y, x * 2, y * 2),"button");
     
     _selectionWindowRect = GUI.Window(_selectionWindowID, _selectionWindowRect, SelectionWindow,  "Select your animal");
     
 }
 
 function SelectionWindow (_selectionWindowID) {
     
     GUI.BeginGroup (Rect (0,0,560,250));
     
     SelectGorilla();
     SelectRhino();
     SelectFrog();
     SelectLion();
     SelectOstrich();
     SelectDonkey();
     SelectZebra();
     SelectKangaroo();
     SelectVaran();
     SelectCamel();
     SeparationLine();
     
     
     GUI.EndGroup ();
     
     // Wrap everything in the designated GUI Area
     GUILayout.BeginArea (Rect (20,250,520,200));
     
     //Make a box so you can see where you are on the screen    
     GUI.Box (Rect(20,30,480,110), "");
     
     for(var i : int = 0; i < 40; i++) {
         GUI.Button (new Rect(25 + (80 * i), 45, 80, 80),"Track " + i.ToString());
                 
     }     
     
     hSliderValue = GUI.HorizontalSlider (Rect (25, 150, 470, 30), hSliderValue, 0.0, 10.0);
     
     GUILayout.BeginVertical();
     GUILayout.Box("Choose Track: " + Mathf.Round(hSliderValue));
     GUILayout.EndVertical();
     
     //Left Arrow
     if (GUI.RepeatButton(Rect(0,30,15,110), "<")) {
         
         if(hSliderValue == 0.0) {
             return;
             Debug.Log(" Slider is at position 0 ");
         
         } else {
             hSliderValue -= 3.0 * Time.deltaTime;
         
             Debug.Log("Clicked the left arrow");
         }
             
     }
 
     //Right Arrow
     if (GUI.RepeatButton(Rect(505,30,15,110), ">")) {
         
         hSliderValue += 3.0 * Time.deltaTime;
         
         Debug.Log("Clicked the right arrow");
     
     }
     
     GUI.Button (Rect (235, 165, 50, 25)," Play ");
     
     
     GUILayout.EndArea();
         
 }
 
Comment
Add comment
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

1 Reply

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

Answer by mohitramani · May 30, 2013 at 12:20 PM

you have mentioned what you are trying to do. could you please mention where exactly are you getting stuck? or rather elaborate your problem a little bit more?

Comment
Add comment · Show 3 · 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 TrewSx · May 30, 2013 at 12:48 PM 0
Share

First thing is that when Choose track is at 0 the left RepeatButton is doing nothing, it remains at value 0, only when i use the right RepeatButton and increase the value from 0 to 1 then the left button is decreasing the value in Choose track and also it is going to negative values, like -1, -2 etc. I want to have it the way that if its on 0 and i use left button then it will go to 20, 19 etc. Something like the Tracks are in the loop that is circling around. If you know what i mean.

Second thing is that i would like to have the GUI.Buttons - Track 0, Track 1 etc inside the GUI.Box (BeginArea?) so they wont be overlapping this GUI.Box like now and while i will be using my RepeatButtons on sides these Track buttons would be smoothly moving as well. Lets say i have only 6 Tracks displayed inside the GUI.Box 0 to 5 and when i press RepeatButton on left the first Track will be 20 second 0, third 1 etc.

English is not my mother tongue, so sorry if you will get a headache from reading this.

avatar image mohitramani · May 31, 2013 at 06:03 AM 0
Share

First Point : Check the comment ::

if (GUI.RepeatButton(Rect(0,30,15,110), "<")) {

     if(hSliderValue == 0.0) { // it seems like hSliderValue is not exactly zero and hence it is not returning
        return;                         // try using the condition (hSliderValue <= 0.0f);
                                            // if you want it to go to 20 the put that code here rather than return
        Debug.Log(" Slider is at position 0 ");
 
     } else {
        hSliderValue -= 3.0 * Time.deltaTime;
 
        Debug.Log("Clicked the left arrow");
     }
 
 }

From your second point what I have understood is that you want a loopable playlist where on pressing the left button you want your track no to decrease and if it becomes less than zero it should go to track 20.

To accomplish this I would say to keep hSliderValue as reference and use that to decide what tracks are to be displayed. you could do something like :

have max value of hSliderValue = totalTracks - noOfTrackDisplayed then based on hSliderValue draw the next 6 buttons which will be displayed in the playlist. for eg if the value of hSliderValue = 5, then loop from 5 till 10 and draw the buttons.

I hope this is what you were looking for!

avatar image TrewSx · Jun 02, 2013 at 02:43 AM 0
Share

This was exactly what i was looking for, thank you very much. You solved my problem

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

14 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

Related Questions

Slider problems + how do I make a brightness slider 2 Answers

Problem implementing volume slider 1 Answer

Slider to control object rotation cause Object reference problem 2 Answers

How to make a mouse sensitivity slider? 1 Answer

4.6 - Using new GUI with JavaScript functions 1 Answer


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