此变换是否为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"); } }