- Home /
How to check if Trigger was touched or 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). Please Help! Thank You!
Answer by salex100m · Nov 17, 2015 at 04:17 AM
Read the API first:
http://docs.unity3d.com/ScriptReference/Collider.html http://docs.unity3d.com/ScriptReference/Collider-isTrigger.html http://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html
You'll still need to figure out how to "touch" the object with the mouse. Usually that means sending a raycast from your mouse click on the screen into the gameworld where it might touch some "trigger" object. There are many tutorials online to help you:
http://lmgtfy.com/?q=Unity3d+tutorial+click+an+object+onscreen
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Player hanging on objects. 0 Answers
How do you trigger a specific collider using OnTriggerEnter? 2 Answers
How to rotate an object like item inspection when entering a trigger? 1 Answer
Distribute terrain in zones 3 Answers