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 /
  • Help Room /
avatar image
0
Question by sun_stealer · Feb 01, 2017 at 04:42 PM · uislidereventsystem

Stop the camera from rotating when dragging a GUI.slider

I have a small UI menu with a bunch of sliders, and I have underlying view with a 3D model. When I hold left mouse button and move mouse the 3D model rotates (kind of 3D viewer). However I don't want my model to rotate when I drag the slider. Is there a way to block further mouse events when slider is being dragged, or check if some UI element is being used to prevent camera rotation?

This question is exactly the same as this one: https://forum.unity3d.com/threads/stop-the-camera-from-rotating-when-dragging-a-gui-slider.186301/

However the proposed solution with GUIUtility.hotControl does not work! hotControl is always 0 in my project, no matter what I do with my sliders and buttons.

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 ampck · Feb 01, 2017 at 07:02 PM

You can put an Image element above the Slider that is only covering the slider, and nothing else.

Then you make that image's Alpha color 0, so it is invisible.

Next, you put a Button component on the Image.

Make a public function on your script with the other mouse events and call it stopMouseEvents();.

Create a public boolean variable sliderIsClicked.

In the stopMouseEvents(); function, put " sliderIsClicked = true; "

In the Update Function, type:

 if (Input.GetMouseButtonUp(0)) {
     
     sliderIsClicked = false;
     
 }

Drag the script onto any GameObject, just make sure it is one that won't get destroyed. I like to make a seperate Empty GameObject specifically for Scripts.

Now to to the Image with the button that you created and scroll down to the bottom of the button and click the little + icon to add an event when the button is clicked.

Drag the GameObject with the script on it from the Hierarchy to the Script Object In the Button component.

Click on the dropdown now and select your script's name and then select stopMouseEvents();.

You should be good to go! The only problem that may arise is now you can't use your slider. This happens because the Image with the button component is above the slider, so Unity is just clicking the Image above the slider, and not the actual slider. To fix this, Instead of putting the Button component with stopMouseEvents(); on a new Image, Put the button component with stopMouseEvents(); on The slider handle that you click and drag.

Comment
Add comment · Show 1 · 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 sun_stealer · Feb 03, 2017 at 12:50 PM 0
Share

Thank you! Yes, I guess this will work. I implemented something like this myself, also with the flag that prevents camera movement when slider is being dragged.

Seems like Unity should have some kind of embedded mechanism for that though...

avatar image
0

Answer by jon_underwood · Apr 21, 2020 at 10:55 AM

Hey @sun_stealer Jason Weimann on YouTube has a great solution here https://www.youtube.com/watch?v=rATAnkClkWU You'll need line 2 and lines 8 to 11

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

127 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 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 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

How to achieve Double Scroll in Unity using EventSystem? 0 Answers

Change Value Of UI Light Slider to Read At Specific Points Of Slider Value 1 Answer

How do I apply a mask to a slider fill so it uses my quadrilateral design 0 Answers

"Clipping", "Jumping" UI slider, attached to the 2d game object ( health bar) 0 Answers

So i want this problem with ui buttons done 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