用户工具

站点工具


侧边栏

script:unityengine:classes:transform:transform.ischildof

Transform.IsChildOf 是否是子对象

JavaScript ⇒ IsChildOf(parent: Transform): bool;
C# ⇒ bool IsChildOf(Transform parent);

Description 描述

Is this transform a child of /parent/?

这个变换是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.

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

JavaScript:

	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");
	}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void OnTriggerEnter(Collider col) {
        if (col.transform.IsChildOf(transform))
            return;
 
        print("Do something here");
    }
}

Transform

script/unityengine/classes/transform/transform.ischildof.txt · 最后更改: 2016/08/02 05:37 (外部编辑)