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 CodingNoob · Jan 26, 2015 at 03:22 PM · rotate objectsliderinputfield

Rotating Gameobject with (hidden) UI slider and Inputfield both positive and negativ

Hi there,

I got a new issue regarding my project, this time it's split in different points:

I need to rotate a gameobject by a slider or slidefunction and inputfield around one axis. Means if i use the slider, the value on the inputfield needs to change accordingly.

I also just want to see a button instead of a whole slider, so basically I'd need to press the button and then change the rotation by sliding left and right. Currently I just positioned the slider above the button which is not intereactable and set the alpha to 0, so it's invisible, but maybe ther is another possibility to achieve this?

The other (and bigger issue) is, that I need the correct rotation in both positive and negative values but currently the object rotates just from 0° - 360° (I know that basically, this is right,as it transfers the negative angles from the negative space to a value from 0°-360°, but I NEED the values as put in in the inputfield or set by the slider for evaluation). Any idea how to manage this?

Thank you in advance!

best regards

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

2 Replies

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

Answer by stevecus · Jan 26, 2015 at 04:17 PM

Just assign a slider max value and min value. As for just wanting the button, create a gameobject>UI>Slider, on the slider delete the image component and delete the child fill area. You can tick use whole numbers on the slider if you don't want floats.

Here,

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class SliderRotate : MonoBehaviour {
 
     public Slider slider;
 
     public float maxRotatePos;
     public float maxRotateNeg;
     public float currentRotation;
 
     void Awake()
     {
         //assign slider attributes

         if(maxRotatePos == 0)
         {
             maxRotatePos = 360;
         }
         if(maxRotateNeg == 0)
         {
             maxRotateNeg = -360;
         }

         slider.maxValue = maxRotatePos;
         slider.minValue = maxRotateNeg;
         currentRotation = 0;
 
     }
 
 
     // Update is called once per frame
     void Update () 
     {
         currentRotation = slider.value;
         transform.eulerAngles = new Vector3(0, currentRotation, 0);
     }
 }
 

Steve.

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 CodingNoob · Jan 27, 2015 at 08:41 AM 0
Share

ok, thank you for that! :) Any idea how to manage the inputfield issue? To link the values of the slider and the inputfield correctly?

avatar image stevecus · Jan 27, 2015 at 11:11 AM 0
Share

Sorry, I don't quite understand, in the inspector you should have the public float of currentRotation. Whatever this value is is what the slider value is and thus you can use this variable to reference the rotation for other scripts. Is that what you want?

avatar image
0

Answer by CodingNoob · Jan 27, 2015 at 03:21 PM

Yes, and your script works well! I just need to be able to change the rotation of the object both with the slider or the inputfield. I linked the slider.value to the input.text, so if the slider.value changes it is shown on the inputfield. But if I want to type the rotation into the textfield, it doesn't work out as I'd like it to.

I set the input.text to set slider.value if changed (slider.value = float.Parse(input.text), and set the Inputfield inspector to accept Decimal Numbers only. But it's having trouble when I try to type in a negative value... I guess there is an issue with converting the string of the Inputfield to a float, is there any other option for this? Also the Placeholder shows up everytime the Textfield is empty (even while still editing the text) and I can't figure out how to reset the value of the Textfield as soon as I klick the Textfield (or: start Editing)...

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 stevecus · Jan 27, 2015 at 04:17 PM 0
Share

Ahh I understand what you want now, apologies. Ill have a look tonight and see what can be done.

avatar image CodingNoob · Jan 28, 2015 at 11:06 AM 0
Share

I managed the issue by using a bool! :D

for the inputfield I added a Event Trigger and the Pointer Click event. By clicking (entering) the inputfield, the bool is set to false and by exiting (EndEdit) to true. The default state of the bool is true. Now, if the bool is false, the Update stops checking for the

input.text = slider.value.ToString(); slider.value = float.Parse(input.text);

part, which was causing the issue as it seems.

Only issue left is reseting the inputfield to an empty value when entering...

avatar image CodingNoob · Jan 28, 2015 at 11:33 AM 0
Share

alright, was easier then thought, fixed it!^^°

avatar image AlanLadd · Jun 03, 2015 at 08:42 PM 0
Share

Can you tell us how you're fix solution looks like to make the Input field! Thank you!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Slider UI rotate image/sprite 1 Answer

[UI] How to best set up connected/dependent sliders(or other user input oriented UI elements)? 1 Answer

Make Inputfield with invisible slide controll? 0 Answers

UI slider "End slide" event 3 Answers

GUI slider and rotation not working 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