Hi Guys,
I’m using a Camera.main.ScreenPointToRay to set a location for my player to move to, but it manages to shoot through my camera scaling slider. How do I make the GUI.VerticalScrollbar block the raycast for the player, or turn off the raycast when the mouse is over the slider?
in my project i added tooltips to the gui elements so i could detect if my mouse is over a button.
GUI.xxx are no 3D objects and do not even exist at the point of time at which you do raycast.
You would instead have a gui manager class that stores all the gui elements rects and offers a method “OverGUI” which checks the provided vector from the mouse position if it is within any of the current rects.
that works very well and in addition its even faster than raycasts
Any advice on dealing with this in Unity iPhone? I have some simple testing GUI elements - e.g. a button to move forward and a button to move back. I also have some raycast code that identifies what the user touches (objects) and reacts to it. I find the same problem as the OP - if there’s an object sitting “behind” one of the buttons within the 3D scene, then my raycast code can hit it “through” the button when the player is attempting to move.
I originally didn’t worry about it until I read this post. I figured there would just be a way to have the GUI “block” the touches from travelling any further and that I’d figure it out later.
Sounds like it’s going to be more difficult than than?
on the iphone, at least unless its a turnbased game, you won’t have OnGUI and GUI.xxx stuff commonly but use a single surface gui system like spritemanager + spriteui, guimanager, …
In the end, I decided to use the scroll wheel for zooming in and out of the game. I’ve still got the slider sitting there, but I haven’t tried any of these tricks yet. I may not need to anymore, but I like where some of these ideas are going. Thanks a bunch everyone. It helped.
Hi Steve,
Can please tell us how did you solve this problem. Since this is a 3 year old post I assume you might have solved this problem in a standard way.