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 zmar0519 · Mar 12, 2011 at 01:45 PM · rotationguisliderrtshorizontal-slider

GUI slider and rotation not working

Hi, everyone, I'm working on an RTS, and I want the player to be able to edit the rotation of the buildings that he got. My building works like this: [Parent Object, with the appropriate name] [model w/ mesh collider] [any other gameobjects for the building]

This script is attatched to the building:

enum TypeOfBuilding { House, Forge, SoldireHouse, Castle, OtherObject } var typeOfBuilding : TypeOfBuilding; var health : int; var Name : String; var selectedColor : Color; class SoldireHouseVars { var creationRate : float; var Soldire : GameObject; var creationPoint : GameObject; } var SoldireHouseVars : SoldireHouseVars = SoldireHouseVars;

@HideInInspector var hSliderValue : float = 0.0;

private var showBox : boolean = false; private var showStats : boolean = false; private var lastCreation : float;

function Update() { if(typeOfBuilding == TypeOfBuilding.SoldireHouse) { if(Time.time > lastCreation) { lastCreation = Time.time + SoldireHouseVars.creationRate; var go : GameObject = Instantiate(SoldireHouseVars.Soldire, SoldireHouseVars.creationPoint.transform.position, transform.rotation); go.AddComponent(Soldire); } } }

function OnMouseOver () { if(showBox != true) { showBox = true; } if(Input.GetMouseButtonDown(0)) { showStats = true; } } function OnMouseExit () { if(showBox == true) { showBox = false; } } function OnGUI() { if(showBox) { GUI.Label(Rect(5, 5, 200, 30), typeOfBuilding.ToString()); } if(showStats) { Time.timeScale = 0; GUI.Box(Rect(Screen.width-150, 0, 150, Screen.height), Name); if(GUI.Button(Rect(Screen.width-150, Screen.height-40, 150, 20), "Delete")) { Destroy(gameObject); Time.timeScale = 1; } if(GUI.Button(Rect(Screen.width-150, Screen.height-20, 150, 20), "Done")) { Time.timeScale = 1; showStats = false; transform.rotation.y = hSliderValue; } hSliderValue = GUI.HorizontalSlider (Rect (Screen.width-140, 30, 135, 30), hSliderValue, 0.0, 360.0); } } function GetName() { return(Name); }

The GUI slider is my problem. When I set it, unless it is up against the very edge (at 0), it is 180 degrees. I want it to be at the value of the slider. How would I do this?

Thanks for the help!!! :)

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 robertbu · May 30, 2013 at 03:10 PM 0
Share

Transform.rotation is a Quaternion...a non-intuitive 4D construct. You don't what to address the components (x,y,z,w) directly. With care you can modify eulerAngles.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by gazza529 · May 30, 2013 at 02:52 PM

hopefully this will help you as i had the same problem

 var hSliderValue : float = 0.0;
 var target : Transform;
 
 function OnGUI () 
 {
    hSliderValue = GUI.HorizontalSlider (Rect (400, 200, 100, 30), hSliderValue, 0.0, 360.0);
 }
  
 function Update ()
 {
    target.transform.rotation.eulerAngles.y = hSliderValue;
 }
Comment
Add comment · Show 1 · 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 robertbu · May 30, 2013 at 02:57 PM 0
Share

You should not set eulerAngles independently. From the reference:

Do not set one of the eulerAngles axis separately (eg. eulerAngles.x = 10; ) since this will lead to drift and undesired rotations.

You could do this ins$$anonymous$$d (assu$$anonymous$$g the other two rotation are 0):

 target.transform.rotation.eulerAngles = Vector3(0.0, hSliderValue, 0.0);

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

1 Person is following this question.

avatar image

Related Questions

how to make a Horizontal slider & toggle in C# with GUI textures 1 Answer

Finish rotation in the same angle of beginning? 1 Answer

GUI Sliders in the same script. Question (Js.) 1 Answer

Curving an Horizontal Slider 2 Answers

How to make a Horizontal Slider slide between resolutions? 3 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