Код:
var attackRange = 30.0; var shootAngleDistance = 10.0; var target : Transform; function Start () { if (target == null && GameObject.FindWithTag("Player")) target = GameObject.FindWithTag("Player").transform; } function Update () { if (target == null) return; // Rotate towards target var targetPoint = target.position; var targetRotation = Quaternion.LookRotation (targetPoint - transform.position, Vector3.up); transform.rotation = Quaternion.Slerp( transform.rotation, targetRotation, Time.deltaTime * 2.0); // If we are almost rotated towards target - fire one clip of ammo var forward = transform.TransformDirection(Vector3.forward); var targetDir = target.position - transform.position; //if (Vector3.Angle(forward, targetDir) < shootAngleDistance) //SendMessage("Fire"); Debug.DrawLine( transform.position, Vector3.forward*20, Color.red); }
Теги: турели