- Home /
How to stop Input.GetKey from cancelling mouse raycasting?
I have a workflow where you can click an object on the screen, and then while holding down your click you can press keyboard keys to activate specific commands for the object you're clicking on.
This is the code that runs the mouse press:
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
bool raycastHit = Physics.Raycast(ray, out hit, maxDistance, layerMask);
This is run once per physics frame, which is how it knows when a hold is happening.
The problem is that the moment that Input.GetKey
or Input.GetKeyDown
returns true, it cancels the mouse's holding pattern, almost like pressing a key cuts off the input from the mouse or cancels the raycast. Because of my design specifications. It would be possible to just "highlight" the object by clicking on it once, but because of my design specifications I need the user to be holding down a click with the mouse while they are pressing other keys to enact commands.
Has anyone had experience with this issue? Is there a way around it?
Your answer
Follow this Question
Related Questions
Raycast calling both if and else statments 0 Answers
Storing vs not storing bool during Raycast ? 1 Answer
Raycasting to pick up an item problem 1 Answer
Some raycasts don't hit the object 0 Answers
Raycast Not Drawing In Target Direction 0 Answers