简体   繁体   English

如何检查是否单击了触发器?

[英]How to check if a trigger is clicked?

Well, I have a gameobject that is a trigger called Object A. 好吧,我有一个名为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). 我希望在runthefunction()触发器)时运行runthefunction()函数。

If you are using a trigger, use the function OnTriggerEnter() 如果使用触发器,请使用函数OnTriggerEnter()

void OnTriggerEnter()
{
    runthefunction();
}

See here for more info: http://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html 请参阅此处以获取更多信息: http : //docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM