Example #1
0
 void OnTriggerExit(Collider other)
 {
     if (other.gameObject.tag == "enemy")
     {
         if (other == target.collider) target = null;
     }
 }
Example #2
0
 void Update()
 {
     if (target != null && target.IsAlive)
     {
        var desiredRotation= Aim(target.transform.position);
         //_tower.transform.rotation = Quaternion.Lerp(_transform.rotation, _desiredRotation,1/* Time.deltaTime * turn_speed*/);
         var angles = _transform.rotation.eulerAngles;
         var diffAngle=Quaternion.Angle(desiredRotation, _transform.rotation);
         if (diffAngle <= 5)
             _transform.rotation = Quaternion.Euler(angles.x, desiredRotation.eulerAngles.y, angles.z);
         else
             _transform.rotation = Quaternion.Euler(angles.x,Mathf.SmoothDampAngle(angles.y, desiredRotation.eulerAngles.y, ref velocity, minimumTimeToReachRarget,maximumRotateSpeed), angles.z);
         foreach (var gun in _guns)
         {
             gun.Shoot();
         }
     }
     else
     {
         foreach (var gun in _guns)
         {
             gun.Stop();
         }
         var vilan = GetClosestObject();
         if (vilan)
             target = vilan.GetComponent<BasicVilan>();
     }
 }