Object.operator bool 布尔运算

static implicit function bool (exists : Object) : bool

Description描述

Does the object exist?

物体是否存在?

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public void Awake() {
	if (typeof(rigidbody))
		Debug.Log("Rigidbody attached to this transform");

	}
}
// check if there is a rigidbody attached to this transform
//检查物体是否添加了刚体?
if (rigidbody)
	Debug.Log("Rigidbody attached to this transform");

is the same as

等同于

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public void Awake() {
	if (rigidbody != null)
		Debug.Log("Rigidbody attached to this transform");

	}
}
// another way to check if a rigidbody is attached to this transform
//另一种方检查物体是否添加了刚体?
if (rigidbody != null)
	Debug.Log("Rigidbody attached to this transform");
最后修改:2010年12月8日 Wednesday 18:47

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。