FindWithTag查找标签,Find查找名称,2个函数均查找游戏对象
GameObject.FindWithTag
GameObject.Find
下面例子移动摄像机,同时追踪球的移动
#pragma strict //code:myhaspl@myhaspl.com //date:2014-08-13 import System; var translate_object:Rigidbody; var li:int=20; var floor_y:int; var mycamera:GameObject; var camera_bh:float; function Start(){ var floor:GameObject=GameObject.FindWithTag("myfloor"); mycamera=GameObject.Find("Ball_camera"); floor_y=-floor.transform.position.y+5; camera_bh=0.01; } function FixedUpdate() { if (translate_object!=null) { if (translate_object.rigidbody.transform.position.y<floor_y){ translate_object.rigidbody.AddForce(0,li,0); } } if (mycamera.transform.rotation.x>-0.10 || mycamera.transform.rotation.x<-0.12) { camera_bh=-camera_bh; } mycamera.transform.Rotate(camera_bh,0,0); }
如下布局:
效果见:
http://mygame.myhaspl.com/test3/test3.html
深入浅出游戏算法(4)-unity3d算法(3)-移动摄像机,布布扣,bubuko.com
深入浅出游戏算法(4)-unity3d算法(3)-移动摄像机
原文地址:http://blog.csdn.net/myhaspl/article/details/38534793