Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void OnMissileShot()
- {
- float closestDistance = 9999;
- Enemy bestTarget = null;
- // Iterate through the scenes list of enemies and check which is the closest to us.
- foreach (Enemy target in GameObject.FindObjectsOfType<Enemy>())
- {
- // check if the target is already tracked
- if (!target.OnCheckMissileTracked())
- {
- Vector2 distance = target.transform.position - transform.position;
- if (distance.magnitude < closestDistance)
- {
- bestTarget = target;
- }
- }
- }
- if (bestTarget != null)
- {
- bestTarget.OnMissileTracked();
- Instantiate(_missle, transform.position, Quaternion.identity).GetComponent<Missile_Behaviour>().OnSetTarget(bestTarget.transform);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment