深入浅出游戏算法(4)-unity3d算法(3)-移动摄像机

FindWithTag查找标签,Find查找名称,2个函数均查找游戏对象

GameObject.FindWithTag

GameObject.Find

下面例子移动摄像机,同时追踪球的移动

#pragma strict
//code:[email protected]
//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-0.10 || mycamera.transform.rotation.x<-0.12) {
       camera_bh=-camera_bh;      
    }
   mycamera.transform.Rotate(camera_bh,0,0);   
}

麦好的AI乐园博客所有内容是原创,如果转载请注明来源

http://blog.csdn.net/myhaspl/


如下布局:

深入浅出游戏算法(4)-unity3d算法(3)-移动摄像机_第1张图片

效果见:

http://mygame.myhaspl.com/test3/test3.html

你可能感兴趣的:(软件与计算)