Object.FindObjectOfType 查找首个Type物体
static function FindObjectOfType (type : Type) : Object
Description描述
Returns the first active loaded object of Type type.
返回Type类型第一个激活的加载的物体。
Please note that this function is very slow. It is not recommended to use this function every frame. In most cases you can use the singleton pattern instead.
请注意这个函数是非常慢的。不推荐在每帧使用这个函数,大多数情况下你可以使用单例模式代替。
See Also: Object.FindObjectsOfType
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void Start() {
GUITexture s = FindObjectOfType(typeof(GUITexture));
if (typeof(s))
Debug.Log("GUITexture object found: " + s.name);
else
Debug.Log("No GUITexture object could be found");
}
}
// Search for any object of Type GUITexture,
// if found print its name, else print a message that says that it was not found.
//搜索任意GUITexture类型的物体
//如果发现打印它的名字,否则打印一条消息说没有发现
function Start() {
var s : GUITexture = FindObjectOfType(GUITexture);
if(s)
Debug.Log("GUITexture object found: " + s.name);
else
Debug.Log("No GUITexture object could be found");
}
最后修改:2010年12月8日 Wednesday 23:51