Player would move when I'm clicking on the inspector in Play mode

Is this normal and how ScreenPointToRay works?
Any workaround if I want my player only moves when my mouse cursor is clicking on the view port?

Sorry I missed this one.
This can be an issue within the Unity Editor itself, but usually this doesn’t extend to a built game.

It can be very annoying, though… You can add this little snippet to the beginning of PlayerController’s Update method to make the cursor stop interacting when off screen:

            Rect screen = new Rect(0, 0, Screen.width, Screen.height);
            if (!screen.Contains(Mouse.current.position.ReadValue()))
            {
                Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
               // Debug.Log($"Not on screen");
                return;
            }
1 Like

Thanks Brian, what a handy snippet!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms