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 Paul Graystone · Dec 12, 2012 at 11:07 AM · guimousedrag

Drag an UI slider (no Unity GUI)

Since Unity GUI is only able to show a 2D Interface, I want to make my own 3D GUI within the game. Therefor I created a few Widgets, including a Slider.

alt text

I want the user to be able to drag the slider with the mouse. The camera is not fixed, the user is free to move within the game. But the slider will be a child of the camera. I have attached a picture that shows the idea with switches.

alt text

Any help is appreciated :)

sliderrendersmall.png (18.6 kB)
interfacesmall_300px.png (73.3 kB)
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
0
Best Answer

Answer by Tourist · Dec 12, 2012 at 01:59 PM

Take a look at : http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnMouseDrag.html

Use a raycast to get the hit point of the mouse on your object and move the slider thumb in that position according to the axis of the slider.

Comment
Add comment · Show 5 · 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 Paul Graystone · Dec 15, 2012 at 05:28 PM 0
Share

Thank you for your answer. I have implemented your recommended functions. This works well, as long as I don't rotate the camera. For better understanding view this image: http://img826.imageshack.us/img826/84/movetoquestion.jpg

The cube (later the slider) is a child of the camera. I want to move the cube in the direction of the red arrows. To achieve this I currently have to move my mouse up and downwards (green arrows). Any solution ideas are appreciated :).

avatar image Tourist · Dec 15, 2012 at 09:09 PM 0
Share

I am not sure to understand. I m ok with the red arrows but I don't understand why the green arrows are there. Are they perpendicular to the camera forward vector? If you use raycast the green arrows wouldn't be there.

avatar image Paul Graystone · Dec 15, 2012 at 10:16 PM 0
Share

The green arrows symbolize the movement of the raycast that is currently necessary to move the slider. Please note the "Camera Preview" window, the Camera is currently nearly perpendicular to the cube. As far as I understand: the green arrows and the forward vector of the camera are not pependicular.

Take a look at his picture: http://img14.imageshack.us/img14/9504/askquestion.jpg The green arrows in the left image show the movement of the cube. The right image shows the necessary mouse drag movement (red arrows) to achieve the translation of the cube. The small green arrows symbolize the expected dragging movement. Hopefully this helps you understand my problem?

avatar image Tourist · Dec 16, 2012 at 09:24 AM 0
Share

With the last image I can't figure out how you can move the slider thumb to the left, except with moving the mouse on the left part of the screen.

The raycast gives you a point on a plane that is the support of your slider. From that you can project the point on the axis of the slider (the green arrows in the last image). The slider will follow the mouse but will be constraint to the axis.

To project the hit point on the slider axis, I ll suggest you use the forward vector of the camera you project on the plane of the slider or something like that in order to validate the calculation for all camera angles.

avatar image Paul Graystone · Dec 16, 2012 at 04:15 PM 0
Share

Thank you for your answer. The hint about the forward vector of the camera led me to my solution. I had to get the local point of my "interface plane". So I just hat to transform the raycast hit point to a local vector:

 var localPos = hitPoint.transform.InverseTransformPoint(hitPoint.point);

Thank you very much for your help. Nevertheless I still have a few other questions about similar to this topic. But I will ask them in a new thread :). Thanks Tourist!

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

10 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

Related Questions

Fixing "Drag GameObject with mouse" script 1 Answer

How to implement Multcolumn draggable ListBox? 0 Answers

GUI Remove focus from an editor text field when clicking elsewhere. 2 Answers

'MouseLook.sensitivityX' is inaccessible due to its protection level. 2 Answers

Drag GameObject with mouse in just one axis 2 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