So I’ve made a Java script(Unity script) to make an object disappear after you click with your left mousebutton. But I only want it when you are in a certain area. So I’ve made the following script:
What this would do is make the object disappear if you’re holding down the mouse button when you enter the trigger. If you enter the trigger first and press the mouse button second, it won’t do anything.
There is an onTriggerStay handler as well that runs every frame while in the trigger:
It is perhaps not efficient to re-check the tag every frame, though, so instead you can use the OnTriggerEnter and OnTriggerExit functions to set a bool to true and false, and then in an Update function you can check if the bool is true and the mouse button is down.