Unity3D圣典3.3版本-中文版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Object.FindObjectOfType 查找首个 Type 物体
# [Object](Object.html "Go to Object scripting documentation").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](Object.FindObjectsOfType.html) * [C#](#) * [JavaScript](#) ``` 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"); } ```
da
2022年5月23日 14:12
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码