返回介绍

MonoBehaviour.OnTriggerStay(Collider) 当停留触发器

发布于 2019-12-18 15:38:04 字数 1144 浏览 1320 评论 0 收藏 0

Description 描述

OnTriggerStay is called once per frame for every Collider other that is touching the trigger .

当碰撞体接触触发器时,OnTriggerStay将在每一帧被调用。

This message is sent to the trigger and the collider that touches the trigger. Note that trigger events are only sent if one of the colliders also has a rigid body attached.

这个消息被发送到触发器和接触到这个触发器的碰撞体。注意如果碰撞体附加了一个刚体,也只发送触发器事件。

JavaScript:

// Applies an upwards force to all rigidbodies that enter the trigger.
 
function OnTriggerStay (other : Collider) { 
	if (other.attachedRigidbody) 
	other.attachedRigidbody.AddForce(Vector3.up * 10); 
} 

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void OnTriggerStay(Collider other) {
        if (other.attachedRigidbody)
            other.attachedRigidbody.AddForce(Vector3.up * 10);
 
    }
}

OnTriggerStaycan be a co-routine, simply use the yield statement in the function.

OnTriggerStay可以被用作协同程序,在函数中调用yield语句。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文