unity3d中Find的用法

在unity3d中用Find可以直接查找组件

例子一:

该脚本时绑在main Camera上的,"/Scene/player"这是在Hierarchy目录下直接找寻Scene
 
if (Physics.Raycast (ray.origin, ray.direction, hit,10)) {
if(hit.transform.name=="player"){

var player = transform.Find("/Scene/player");
print (player.position);

}
 
例子二:
该脚本时绑在main Camera上的,"Scene/player"这是在main Camera目录下直接找寻Scene
 
if (Physics.Raycast (ray.origin, ray.direction, hit,10)) {
if(hit.transform.name=="player"){

var player = transform.Find("Scene/player");
print (player.position);

}
 
 
原文地址:https://www.cnblogs.com/android-blogs/p/6038247.html