Version: 2017.3

Collider.OnTriggerStay(Collider)

切换到手册

参数

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

描述

OnTriggerStay is called almost all the frames for every Collider other that is touching the trigger.

此消息被发送到该触发器以及接触该触发器的碰撞体。 注意,如果其中一个碰撞体还附加了刚体,则仅发送触发器事件。触发器事件将发送到已禁用的 MonoBehaviours,以便允许启用 Behaviours,以响应碰撞。

Note: OnTriggerStay function is on the physics timer so it won't necessarily run every frame.

using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
    // Applies an upwards force to all rigidbodies that enter the trigger.
    void OnTriggerStay(Collider other)
    {
        if (other.attachedRigidbody)
            other.attachedRigidbody.AddForce(Vector3.up * 10);
    }
}