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 RandomUser123 · Aug 26, 2014 at 12:00 PM · guiunity4.6horizontal-slider

Help appreciated with new UI system (4.6 beta)

I have this text below which uses unitys old GUI system, when I move the slider, it controls the direction my object is facing, I'm having some trouble incorporating it into the new GUI system.

If anyone has used the new GUI system enough to understand it and could tell me how I could work this into the horizontal slider system, I'd appreciate it.

Is it controlled by code like this? Or does the new method work from the inspector?

 public class ProjectileTest : MonoBehaviour {
 
     public float hSliderAngleValue = 0.0f;
     public float hSliderPowerValue = 0.0f;
     public float sliderDirectionValue = 5.0f;
     
     // Update is called once per frame
     void Update () 
     {
         transform.rotation = Quaternion.Euler (-hSliderAngleValue, sliderDirectionValue, 0);
 
     }
     
     void OnGUI()
     {
         //GUI.Box(new Rect(Screen.width-120,Screen.height-240,100,50),"Angle");
         hSliderAngleValue = GUI.HorizontalSlider (new Rect (Screen.width-120, Screen.height-180, 100, 20), hSliderAngleValue, 0.0f, 80.0f);
     }
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 HarshadK · Aug 26, 2014 at 12:14 PM

The new GUI is not accessed from the OnGUI. These two are different.

You create the slider from the editor (even though is is possible it is rather cumbersome to create new GUI elements from code).

Then you can call your function that changes the direction the object is facing from the On Value Changed event Event Trigger.

Also on your code that changes the direction of object you can get the reference to your Slider script component (One great thing about new GUI system is that it uses game objects and components itself to construct the GUI) and can change the direction according to that value.

Something like:

 using UnityEngine.UI; //Don't forget this
 
 public class RotationTest : MonoBehaviour {
  
     public Slider slider;
 
     public OnSliderValueChanged()
     {
         // You can access the current value of slider using slider.value
         // And set the direction using your slider value accordingly
     }
 }

You can also check a video on using sliders in the Unity's learn section at UI Slider

Comment
Add comment · Show 2 · 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 RandomUser123 · Aug 26, 2014 at 12:39 PM 0
Share

Thanks @Harshad$$anonymous$$, that helped a lot, I have it up and running again with the new UI, thanks a million

avatar image HarshadK · Aug 26, 2014 at 12:40 PM 0
Share

Always happy to help. :-)

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

22 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

Related Questions

How to Lock a Slider Value 1 Answer

How to make a Horizontal Slider slide between resolutions? 3 Answers

Horizontal Slider issue 0 Answers

Unity 4.6 InputFields need help 1 Answer

move object with slider 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