- Home /
How to disable an object by clicking outside anywhere else?
Hello,
I'm building a space game and I want when I click in empty space for the red indicator I placed around my character to be SetActive (false), in other words for the red indicator to turn off.
When you click on the object(OnMouseDown) that has the red indicator over it, the red indicator object is lit, when I click outside the object, I want the red indicator over my character object to be disabled. How?
Answer by Oribow · May 08, 2016 at 12:19 AM
Replace you MouseOver (just assuming) usage with a single raycast. Just cast that ray, if the mouse is clicked and check what you hit.
void Update () {
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), distance))
{
//Check what we clicked on
}
else
{
//Didnt clicked on anything
}
}
}
Your answer
Follow this Question
Related Questions
Conflicting Box Colliders 0 Answers
Gameobject flickering (Trigger issues?) 0 Answers
Making A Debug.Log depending on what GameObject is active 1 Answer
Can't click gameobject when over another trigger? 1 Answer
Reference creator of gameObject 1 Answer