예제 #1
0
        public void UpdateTrajectory()
        {
            if (!gameObject.activeInHierarchy)
            {
                return;
            }

            float moveDistance = speed * Time.fixedDeltaTime;

            distanceTraveled   += moveDistance;
            transform.position += transform.forward * moveDistance;

            float previousSqrDistance = sqrDistanceToTarget;

            sqrDistanceToTarget = sphereCollider.bounds.SqrDistance(target.transform.position);

            if (previousSqrDistance < sqrDistanceToTarget)
            {
                nearMiss = true;
            }

            if (sphereCollider.bounds.Intersects(target.bounds))
            {
                gameObject.SetActive(false);
                OnTargetShot.Invoke();
            }

            if (distanceTraveled >= maxTravelDistance)
            {
                gameObject.SetActive(false);
                OnTargetMissed.Invoke(nearMiss);
            }
        }
예제 #2
0
 public void Shot()                            // shooting target. Invoking events with (this) passing
 {
     OnTargetShot?.Invoke(this);
     gameObject.SetActive(false);
 }