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);

}

你可能感兴趣的:(unity3d)