-
Notifications
You must be signed in to change notification settings - Fork 0
/
SquadManager.cs
81 lines (70 loc) · 1.58 KB
/
SquadManager.cs
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using UnityEngine;
using System.Collections.Generic;
public class SquadManager : MonoBehaviour {
// Also handles Game Over
public List<AI_Agent> m_agentsList;
public List<AI_Agent> m_squadList;
int DeadAgentCounter;
void Start ()
{
m_agentsList = new List<AI_Agent>();
m_squadList = new List<AI_Agent>();
/// List of ALL agents
foreach (AI_Agent obj in GameObject.FindObjectsOfType<AI_Agent>())
{
m_agentsList.Add(obj.GetComponent<AI_Agent>());
}
/// List of SQUAD agents
foreach(GameObject obj in GameObject.FindGameObjectsWithTag("Squad"))
{
m_squadList.Add(obj.GetComponent<AI_Agent>());
}
}
void Update()
{
/// Track agents for KIAs
foreach(AI_Agent agent in m_agentsList)
{
float AgentLife = agent.GetComponent<Health>().GetHealth();
if (AgentLife <= 0.0f)
{
DeadAgentCounter++;
}
else { DeadAgentCounter = 0; }
}
/// All agents killed -> GameOver!
if (DeadAgentCounter >= m_agentsList.Count)
{
Application.LoadLevel("EndScreen");
}
}
public void Notify(GameObject threat)
{
foreach (AI_Agent agent in m_squadList)
{
bool doNotify = true;
if (agent.Vision.Threats.Count == 0)
{
doNotify = true;
}
else foreach(GameObject obj in agent.Vision.Threats)
{
if (threat == obj)
{
doNotify = false;
}
}
if (doNotify)
{
agent.Vision.Threats.Add(threat);
}
}
}
public void StandDown()
{
foreach (AI_Agent localAgent in m_squadList)
{
localAgent.Vision.Threats.Clear();
}
}
}