1.GameObject.Find

函数原型:

public static GameObject Find(string name);
说明:1.GameObject只能查找到active的物体
   2.如果name指定路径,则按路径查找;否则递归查找,直到查找到第一个符合条件的GameObject或者返回null
 
2.transform.Find
函数原型:

 
public Transform Find(string n);
说明:1.transform.Find用于查找子节点,它并不会递归的查找物体,也就是说它只会查找它的子节点,并不会查找子节点的子节点。
用代码验证:

 public class TestFind : MonoBehaviour
{ public string name = "";
private void Start()
{
Transform t = transform.Find(name);
if(t != null)
print("找到了");
else
{
print("没找到");
}
}
}

说明:TestFind脚本挂在GameObject物体上。

1.name为a, 输出找到了

2.name为aa,输出没找到

3.name为b,输出找到了

4.name为bb,输出没找到

补充:在实际开发中可能遇到这样的情况,给定一个节点,在这个子节点中递归的查找符合条件的节点。transform.Find不能递归查找,不能直接使用,GameObject.Find又做了很多无用功,关键若是重名还不一定能满足需求。于是我们可以自己写一个递归程序:

  public static Transform FindChildRecursively(Transform parent, string name)
{
Transform t = null;
t = parent.Find(name);
if (t == null)
{
foreach (Transform tran in parent)
{
t = FindChildRecursively(tran, name);
if (t != null)
{
return t;
}
}
} return t;
}
}

GameObject.Find与Transform.Find的区别的更多相关文章

  1. Gameobject.Find和Transform.Find应用区别

    using UnityEngine;using System.Collections; public class test : MonoBehaviour{ private GameObject ro ...

  2. zoom和transform:scale的区别

    小tips: zoom和transform:scale的区别 这篇文章发布于 2015年11月3日,星期二,00:52,归类于 css相关. 阅读 7876 次, 今日 8 次 by zhangxin ...

  3. vector3.forward和transform.forward的区别!

    http://blog.163.com/bowen_tong/blog/static/20681717420146654927791/ vector3.forward和transform.forwar ...

  4. css中zoom和transform:scale的区别

    css中zoom和transform:scale的区别 关于zoom: 以前只是看到别人的代码中用过zoom,自己从未使用过,今天在探究ie7兼容inline-block时,发现里面提到了zoom.下 ...

  5. 【Unity3D游戏开发】GameObject.Find()、Transform.Find查找隐藏对象 (十)

    GameObjectFindTransformFind查找游戏对象 前置条件 相关API 1 GameObjectFind 2 TransformFind 3 其他查找 实际测试 即使隐藏root节点 ...

  6. Unity3d vector3.forward和transform.forward的区别!

    原文连接: http://blog.csdn.net/kaluluosi111/article/details/17206655 在unity3d中有2个forward,一个是vector3.forw ...

  7. 小tips: zoom和transform:scale的区别

    小tips: zoom和transform:scale的区别 转自 张鑫旭 前端大神 by zhangxinxu from http://www.zhangxinxu.com本文地址:http://w ...

  8. gameObject, vector and transform

    调用其它组件中成员 通过GameObject(游戏物体). Base class for all entities in Unity scenes.  是Unity场景里面所有实体的基类. 可以理解为 ...

  9. zoom和transform:scale()的区别

    zoom和transform:scale()都可以用于缩放,目前移动端存在各种各样不同屏幕大小的手机,为了兼容不同宽度的屏幕,我们可以基于某一屏幕宽度大小(比如iPhone5的320,这个根据设计稿来 ...

随机推荐

  1. LeetCode 766 Toeplitz Matrix 解题报告

    题目要求 A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element. Now ...

  2. LeetCode 944 Delete Columns to Make Sorted 解题报告

    题目要求 We are given an array A of N lowercase letter strings, all of the same length. Now, we may choo ...

  3. pyqt5-day1

    pyqt5做为Python的一个模块,它有620多个类和6000个函数和方法.这是一个跨平台的工具包,它可以运行在所有主要的操作系统,包括UNIX,Windows,Mac OS.pyqt5是双重许可. ...

  4. Lua: 给 Redis 用户的入门指导(转)

    add by zhj : Lua与Multi/EXEC的功能比较像,在执行过程中,redis不会执行其它命令,这就不会有并发访问的问题, 这是非常好的.但Multi/EXEC要求所有命令都是独立的,后 ...

  5. redis缓存和mysql数据库同步

    附redis关于缓存雪崩和缓存穿透,热点key 穿透 穿透:频繁查询一个不存在的数据,由于缓存不命中,每次都要查询持久层.从而失去缓存的意义. 解决办法: 持久层查询不到就缓存空结果,查询时先判断缓存 ...

  6. jquery的widget源代码剖析

    dialog_obj(别名): Widget_obj(别名): 调用widget方法 $.widget("ui.dialog",dialog_obj); // jquery.ui. ...

  7. 初识Shell与Shell脚本

    初识Shell Shell 是一个用 C 语言编写的程序,Shell 既是一种命令语言,又是一种程序设计语言. Shell 是指一种应用程序,这个应用程序提供了一个界面,用户通过这个界面访问操作系统内 ...

  8. 【开发者笔记】python中的类方法(@classmethod)和静态方法(@staticmethod)

    在java.c#等高级语言中我们用static来定义静态方法和静态变量,那么在python中如何定义静态方法和静态变量呢. python提供了@classmethod和@staticmethod来定义 ...

  9. abap调用代码块

    1:abap 调用代码块. *&---------------------------------------------------------------------* *& Re ...

  10. UML序列图的理解:

    UML序列图的理解:UML序列图是指一个对象的方法在处理过程中调用其他对象的图:重点是要突出调用其他对象的序列: