- Home /
Hide cursor and stop interaction
I have set up a basic dynamic control system. The player can use the mouse and keyboard or controller. When they start using the controller several things happen, but the most relevant thing here is that the mouse is hidden. That works fine. What is wrong is that the mouse still interacts with the UI under it while hidden. How do I stop this from happening?
I'm looking for some sort of setting or something that I'm missing. I certainly can not go through every script and remove raycast target because I need mouse and keyboard control as well. I only want to block mouse interaction when the cursor is hidden.
Using 5.3. Code is in C# but it's just the normal Cursor.visible. I have tried locking the cursor but that is somehow worse as the cursor goes to the center and interacts with everything under the center point.
Thanks.
Answer by LLIV · Jan 28, 2016 at 04:51 PM
Hmmmmm. You could try and do two things here. 1. You could try finding a dead zone and locking the mouse there. 2. You said you hide the mouse whenever the controller is used. I assume this involves some sort of Boolean variable. It might take a while but you could put a if statement in your scripts that says if the controller is being used stop taking input from the mouse. This would stop it from interacting with the scene. thats what I would do but I'm never right! :)
Do you know of any way to move the mouse through code? When I search for how to do that it always requires some Windows specific API usage which I can not abide.
Hiding the mouse is as simple as setting -> Cursor.visible = false;
I'm hoping to avoid using the strategy you mentioned. It's a bunch of extra work that shouldn't be necessary. I'm not saying it's a bad idea, I'm just saying that there hopefully is a better solution. If there isn't, Unity should put one in.
I appreciate your thoughts :)
I found a solution. The input system I am using has a simple bool I can set on or off to disable mouse interaction. Thanks for the help.
@Nakor, Could you expand a little bit more on that? (I have a similar issue)
Your answer
Follow this Question
Related Questions
UI mouse click prevent default / stop propagation. (Block mouse events of other scripts) 3 Answers
Native resolution fullscreen breaks UI clicks 0 Answers
How do i disable my buttons while dragging ScrollRect? 0 Answers
Advice for making a 2D Dialogue System? 2 Answers
PauseMenu - Camera moves in pausemenu 0 Answers