diff options
author | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
commit | 766cdff5ffa72b65d7f106658d1603f47739b2ba (patch) | |
tree | 34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/Chase.cs |
+ init
Diffstat (limited to 'GameCode/Chase.cs')
-rw-r--r-- | GameCode/Chase.cs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/GameCode/Chase.cs b/GameCode/Chase.cs new file mode 100644 index 0000000..1101987 --- /dev/null +++ b/GameCode/Chase.cs @@ -0,0 +1,62 @@ +using UnityEngine; +using UnityEngine.Events; + +public class Chase : MonoBehaviour +{ + public UnityEvent turnOnEvent; + + public UnityEvent turnOffEvent; + + public UnityEvent switchTargetEvent; + + private Player player; + + private LineEffect lineEffect; + + private bool isOn; + + private Player currentTarget; + + private void Start() + { + lineEffect = GetComponentInChildren<LineEffect>(includeInactive: true); + player = GetComponentInParent<Player>(); + } + + private void Update() + { + Player player = PlayerManager.instance.GetClosestPlayerInTeam(base.transform.position, PlayerManager.instance.GetOtherTeam(this.player.teamID), needVision: true); + if ((bool)player && (Vector2.Angle(player.transform.position - base.transform.position, this.player.data.input.direction) > 70f || this.player.data.input.direction == Vector3.zero)) + { + player = null; + } + if ((bool)player) + { + if (currentTarget != this.player) + { + currentTarget = this.player; + switchTargetEvent.Invoke(); + lineEffect.Play(base.transform, player.transform); + } + if (!isOn) + { + isOn = true; + turnOnEvent.Invoke(); + } + } + else + { + if (isOn) + { + isOn = false; + turnOffEvent.Invoke(); + } + if (lineEffect.isPlaying) + { + lineEffect.Stop(); + lineEffect.gameObject.SetActive(value: false); + } + currentTarget = null; + } + } +} |