Ibrahim Munaser
Ibrahim Munaser

Reputation: 1

How to check if a trigger is clicked?

Well, I have a gameobject that is a trigger called Object A.

I want to know how to find out if the trigger was clicked. if I do

   void Update()
   {
       if( Input.GetMouseButton(0))
         {
               runthefunction();
         }
   }

then it just waits for me to click anywhere.

I want the runthefunction() function to run when I click on ObjectA (the trigger).

Upvotes: 0

Views: 62

Answers (1)

Tom
Tom

Reputation: 2472

If you are using a trigger, use the function OnTriggerEnter()

void OnTriggerEnter()
{
    runthefunction();
}

See here for more info: http://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html

Upvotes: 1

Related Questions