Question

Is there a way in Unity to disable mouse inputs to a GameObject without removing/disabling the collision box?

I want to write a script that would ignore the mouse input of the object after it was pressed once. It's not hard to do so within the scope of the script, but I want other scripts on that objects to ignore mouse input without modifying all the other scripts.

Was it helpful?

Solution

According to the OnMouseDown documentation

This function is not called on objects that belong to Ignore Raycast layer.

So, one way of doing this is switching the layer of the object to Ignore Raycast.

this.gameObject.layer = LayerMask.NameToLayer("Ignore Raycast");

But if you have other functionality that depends on raycasting, those will be disabled too (unless they are raycasting in other layers).

OTHER TIPS

That could be achieved by placing a script which validates/filters the inputs. It could be a single bool reveiceInput in an another script which is read every time you get input. So if that receiveInput is false after the first mouseDown the others won't affect it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top