- 最后登录
- 2018-6-29
- 注册时间
- 2011-7-1
- 阅读权限
- 20
- 积分
- 359
- 纳金币
- 335582
- 精华
- 0
|
var lookAtDistance = 15.0;
var distance;
//Target to be aimed at
var findTarget : Transform;
//Projectile/Ammo from Turret
var ammoPrefab : Transform;
//Tells Unity When to fire
private var fireCycle : float;
//Fire Delay
var fireDelay : float;
function update() {
distance = Vector3.Distance(findTarget.position, transform.position);
if(distance < lookAtDistance){
//Follows target
transform.LookAt(findTarget);
}
//Check if Turret can fire
if(Time.Time > fireCycle){
//Fire
shoot();
//Update Firing Time
fireCycle = Time.Time + fireDelay;
}
}
//Turret Fires
function shoot(){
var ammo = Instantiate(ammoPrefab.transform.Find("fireOutput"),transform.position,
Quaternion.identity);
ammo.rigidbody.AddForce(transform.forward * 500);
}
|
|