blob: 99fca28ef7ed875ac0f7c7eba43f7e969ef53b67 (
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
|
using System;
using UnityEngine;
using UnityEngine.Events;
public class LineOfSightTrigger : MonoBehaviour
{
public UnityEvent turnOnEvent;
public UnityEvent turnOffEvent;
public UnityEvent switchTargetEvent;
public Action<Player> turnOnAction;
public Action<Player> switchTargetAction;
public Action turnOffAction;
private Player player;
private bool isOn;
private Player currentTarget;
private void Start()
{
player = GetComponentInParent<Player>();
}
private void Update()
{
Player closestPlayerInTeam = PlayerManager.instance.GetClosestPlayerInTeam(base.transform.position, PlayerManager.instance.GetOtherTeam(player.teamID));
if ((bool)closestPlayerInTeam)
{
if (currentTarget != player)
{
switchTargetEvent.Invoke();
switchTargetAction?.Invoke(player);
currentTarget = closestPlayerInTeam;
}
if (!isOn)
{
isOn = true;
turnOnAction?.Invoke(player);
turnOnEvent.Invoke();
}
}
else
{
if (isOn)
{
isOn = false;
turnOffAction?.Invoke();
turnOffEvent.Invoke();
}
currentTarget = null;
}
}
}
|