Version: 2022.2
言語: 日本語
public bool isTrigger ;

説明

Specify if this collider is configured as a trigger.

トリガーにすると、Rigidbody の衝突判定を行わなくなります。ですが、Rigidbody がトリガーの範囲内に「入り」、「出る」ときにコールバックとして OnTriggerEnterOnTriggerExitOnTriggerStay が呼び出されます。

using UnityEngine;

public class Example : MonoBehaviour { Collider m_ObjectCollider;

void Start() { //Fetch the GameObject's Collider (make sure they have a Collider component) m_ObjectCollider = GetComponent<Collider>(); //Here the GameObject's Collider is not a trigger m_ObjectCollider.isTrigger = false; //Output whether the Collider is a trigger type Collider or not Debug.Log("Trigger On : " + m_ObjectCollider.isTrigger); }

void OnMouseDown() { //GameObject's Collider is now a trigger Collider when the GameObject is clicked. It now acts as a trigger m_ObjectCollider.isTrigger = true; //Output to console the GameObject’s trigger state Debug.Log("Trigger On : " + m_ObjectCollider.isTrigger); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961