0

I have a large slider within Unity that manipulates the current position of a animated model.

When I drag the slider around, because it reacts to the click and drag of right mouse click, it also moves the camera as well.

How do I stop this from happening, so when dragging UI elements it doesn't interfere with the camera?

Many thanks

Tim Hanson
  • 251
  • 1
  • 5
  • 17
  • you have encountered the biggest pain in the ass in Unity. it's the single biggest F-up by Unity ... and that's saying something. Also, please "vote up" my answer on the other page as it does not have many votes which gives me tears! also note the link there to "BoredMormon"'s video tutorial. Expect to spend some days mastering this problem. perhaps use my "quick dirty" solution to get you through at first --- but it does not always work. sorry for the sad news – Fattie Feb 24 '16 at 14:27
  • ah great, I look forward to this one. – Tim Hanson Feb 24 '16 at 14:36
  • I was wondering, could I not get it so that when ever it knows that the slider is being dragged it just disables the cameras script to have it move? – Tim Hanson Feb 24 '16 at 14:37
  • no, won't work. you have to "ignore" clicks on the UI elements. is huge PITA – Fattie Feb 24 '16 at 14:39
  • thanks for the upvote :-) :-) – Fattie Feb 24 '16 at 14:40

1 Answers1

2

There's a relatively simple solution to this;

if(!EventSystem.current.IsPointerOverGameObject())
    ...

This returns true when the mouse cursor is over a UI element, and hence if you include the above if statement in your camera controller before it's movement/rotation logic, only the slider will move.

Hope this helped you.

MrDiVolo
  • 151
  • 5