summaryrefslogtreecommitdiff
path: root/GameCode/Chase.cs
blob: 11019872f2bcb0fcce5a3326686c6a9b3d2b9f02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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;
		}
	}
}