Transform.IsChildOf 是否子物体


function IsChildOf (parent : Transform) : bool

Description描述

Is this transform a child of parent?

这个变换是父级的子物体?

就是说判断这个物体是否是子物体。

Returns a boolean value that indicates whether the transform is a child of a given transform.  true if this transform is a child, deep child (child of a child) or identical to this transform, otherwise false.

返回布尔值,是指这个变换是否是指定变换的子物体。如果这个变换是一个子物体、深层子物体(孩子的孩子)或者同级这个变换,返回真,否则返回假。

  • C#

  • JavaScript

using UnityEngine;using System.Collections;public class example : MonoBehaviour {void OnTriggerEnter(Collider col) {if (col.transform.IsChildOf(transform))return;print("Do something here");}}
function OnTriggerEnter (col : Collider) {// 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");}


,