Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Halo500 · Jan 12, 2016 at 06:46 AM · guislidervector2sensitivityhorizontal-slider

Using GUI.HorizontalSlider on Vector2?

Hello! I am attempting to create a Sensitivity Slider with GUI.HorizontalSlider by grabbing the values from another script's line: public Vector2 MouseLookSensitivity = new Vector2(5.0f, 5.0f);

I'm getting the error cannot convert 'UnityEngine.Vector2' expression to type 'float' and I would like some guidance on what to do differently to achieve my goal. :)

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
1
Best Answer

Answer by allenallenallen · Jan 12, 2016 at 07:37 AM

The error means exactly what it says.

The variable MouseLookSensitivity is a Vector2: http://docs.unity3d.com/ScriptReference/Vector2.html

On the other hand, GUI.HorizontalSlider is a float: http://docs.unity3d.com/ScriptReference/GUI.HorizontalSlider.html

You can't set a float to a Vector2.

Why exactly do you need the MouseLookSensitivity variable for? It has two floats since it's a Vector2. Do you perhaps want to use them as position values? Or slider values for the GUI.HorizontalSlider? Look at the parameters for GUI.HorizontalSlider closely.

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 Halo500 · Jan 12, 2016 at 08:20 AM 0
Share

I want to use the two floats from $$anonymous$$ouseLookSensitivity as slider values for the GUI.HorizontalSlider. Similar to as if I was trying to use a GUI.HorizontalSlider to change the Rotation Speed x and y values from the $$anonymous$$obile First Person Control script.

Is there a different method to doing this or some sort of conversion?

avatar image allenallenallen Halo500 · Jan 12, 2016 at 10:11 AM 0
Share

Well, obviously you need two different sliders to get the X and Y mouse sensitivity.

Something like this should work. To get the X and Y values of a Vector2, simple do Vector2.x and Vector2.y.

 public float x$$anonymous$$ouseSlider;
 public float y$$anonymous$$ouseSlider;
 
 void OnGUI() {
         x$$anonymous$$ouseSlider = GUI.HorizontalSlider(new Rect(25, 25, 100, 30), $$anonymous$$ouseLookSensitivity.x, 0.0F, 10.0F);
         y$$anonymous$$ouseSlider = GUI.HorizontalSlider(new Rect(25, 25, 100, 30), $$anonymous$$ouseLookSensitivity.y, 0.0F, 10.0F);
 }

avatar image
1

Answer by Eno-Khaon · Jan 12, 2016 at 11:10 AM

As an alternative approach, if you intend to have a single "sensitivity" scale for both X and Y axes, you can use a float to maintain your entire sensitivity and multiply the Vector2 by that value.

 float mouseLookSensitivity;
 Vector2 mouseScale;
 
 void OnGUI()
 {
     mouseLookSensitivity = GUI.HorizontalSlider(**DETAILS HERE**);
     mouseScale = Vector2.one * mouseLookSensitivity; // Vector2.one used under the assumption of equivalency
 }

mouseScale may not even be necessary, depending on implementation. Alternatively, mouseScale could also be given two separate values to provide a different degree of sensitivity to each axis.

Comment
Add comment · 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

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

47 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 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 avatar image avatar image avatar image

Related Questions

GUI slider and rotation not working 1 Answer

how to make a Horizontal slider & toggle in C# with GUI textures 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