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 squak · Apr 10, 2015 at 10:24 PM · c#guiworld spaceexecute

ExecuteEvents with uGui slider

I'm using a world space canvas with a custom world space cursor I made for a VR project (just a cursor graphic pushed around by the mouse scroll values). Using the graphic raycaster, I determine which UI elements are underneath the cursor, and using ExecuteEvent I simulate clicks on those elements.

The issue I'm running into is that the slider UI component doesn't seem to respond to triggering "click" events on it. I'm specifically calling Execute with ExecuteEvents.pointerClickHandler on it and producing no effect.

Does anyone know how to get this thing to slide, aside from clicking on it with the actual mouse cursor?

Note: this is for Unity 5 in C#

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 squak · Apr 13, 2015 at 01:05 PM

I ended up going with a hacky approach that works. I look at the gameObject.name of the raycastAll results and if the object is a slider background, find the handle, position it to the mouse pointer, compare the position of the handle with the position and width of the slider to determine the percentage of the whole the slider is slid, multiply that by the max value, and set the slider to that value.

That way each slider can have different "onValueChange" handlers and I can treat them all the same. My code looks like this:

  if (name == "SliderBackground") {
     
                                 GameObject sliderBackground = result.gameObject;
                                 Transform sliderTransform = sliderBackground.transform.parent;
                                 GameObject sliderGameObject = sliderTransform.gameObject;
     
                                 GameObject handleToSlide = sliderTransform.Find ("Handle Slide Area/Handle").gameObject;
                                 Vector3 handlePosition = handleToSlide.transform.position;
                                 handlePosition.x = uiMouseWorldPosition.x;
                                 handleToSlide.transform.position = handlePosition;
     
   
                                 RectTransform sliderBGRectTransform = sliderBackground.GetComponent<RectTransform>();
                                 float leftBound = sliderBGRectTransform.rect.xMin;
                                 float rightBound = sliderBGRectTransform.rect.xMax;
     
                                 float sliderProportion = (uiMouseLocalPosition.x - leftBound)/(rightBound - leftBound);
 
                                 Slider slider = sliderGameObject.GetComponent <Slider>();
                                 slider.value = sliderProportion * slider.maxValue;    
                             }


uiMouseLocalPosition and uiMouseWorldPosition are the .localPosition and .position of my mouse object on the world space canvas (respectively).

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

2 People are following this question.

avatar image avatar image

Related Questions

ExecuteEvents.Execute pass object to from ui 1 Answer

Multiple Cars not working 1 Answer

GUI buttons not appearing on Destroy 1 Answer

Distribute terrain in zones 3 Answers

Erroe when resizing GUITextures in C# file 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