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