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 16, 2012 at 04:57 PM · javascriptguidrag

Set dragging boundaries for a self-made slider

I try to develop a 3D GUI (since the Unity GUI is only able to show 2D elements). Hence I have attached a plane and two sliders as a child to my main camera. The sliders represent values from 0% to 100%. Therefor they have to have limits. The image below shows the setup:

alt text

Thanks to Tourist (see here) I am able to drag my sliders vertically by mouse. Currently it is possible to drag the slider up to the edge of the dark gray plane. But I want them to stay in the light gray frame.

My current solution is not a really good one. I have two variables in local space:

 var bottomBound = -0.351691; (self measured)
 var topBound    = -1.135893; (self measured)

If the next position of the sliders would exceed these bounds, dragging would be suppressed. I do the measuring by shooting a raycast and printing the local coordinates of the vector.

     var localPos = hitPoint.transform.InverseTransformPoint(hitPoint.point);
     Debug.Log("(x,y,z) = (" + localPos.x + "," + localPos.y + "," + localPos.z + ")");    

But there is one major problem with this solution. Even if my measurements were pretty good, the slider still can move beyond the edges of the light gray area. I suspect that this is due to the position of the pivot point.

What can I do to keep the slider in the wished area?

PS: Can I get the width and height of the sliders?

ask-unity.jpg (131.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

Answer by jeeyoh · Apr 01, 2013 at 09:03 AM

you can always try using Mathf.Clamp to limit their movements

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

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

Setting Scroll View Width GUILayout 1 Answer

Error: you are pushing more GUIClips than you are poping. 1 Answer

Unity freezes when changing GUI.Color.a 1 Answer

How to implement Multcolumn draggable ListBox? 0 Answers

How do I use function OnGui to display a 2D texture? 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