Version: 2022.2

MonoBehaviour.OnTriggerStay(Collider)

切换到手册

参数

other 该碰撞中涉及的其他 Collider。

描述

对于接触触发器的每一个 Collider /other/,每次物理更新调用一次 OnTriggerStay。

**注意:**如果其中一个碰撞体还附加了刚体,则仅发送触发器事件。触发器事件将发送到已禁用的 MonoBehaviour,以便允许启用 Behaviour,以响应碰撞。

此消息被发送到该触发器以及接触该触发器的碰撞体。

// Applies an upwards force to all rigidbodies that enter the trigger.

using UnityEngine; using System.Collections;

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

OnTriggerStay 可以作为协同程序使用 - 在函数中使用 yield 语句即可。