Version: 2021.3
public bool IsChildOf (Transform parent);

描述

该变换是否为 parent 的子项?

返回一个布尔值,指示变换是否为给定变换的子项。 如果该变换为其子项、深层子项(子项的子项)或与该变换相同,则返回 true,否则返回 false。

using UnityEngine;

public class Example : MonoBehaviour { void OnTriggerEnter(Collider col) { // Ignore trigger events if between this collider and colliders in children // Eg. when you have a complex character with multiple triggers colliders. if (col.transform.IsChildOf(transform)) { return; }

print("Do something here"); } }