WUT_Computer_Science/Programming/E-PSYOPS/theProject/Assets/Scripts/Managers/SquadManager.cs

51 lines
1.5 KiB
C#
Raw Normal View History

// TEMP CODE JUST FOR SHOWCASE PURPOSES
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SquadManager : MonoBehaviour
{
[SerializeField] GameObject squadPrefab;
Squad playerSquad;
Squad enemySquad;
Vector2Int playerSpawnCoords = Vector2Int.up; //TEMP SPAWN BY BASE
private void Awake()
{
2022-05-23 14:30:01 +02:00
playerSquad = Instantiate(squadPrefab).GetComponent<Squad>();
playerSquad.gameObject.name = "Player Squad";
playerSquad.transform.SetParent(transform);
2022-05-23 15:13:48 +02:00
playerSquad.SetOwnTeam(Entity.Team.Ally);
playerSquad.gameObject.AddComponent<SoldierSpawning>();
playerSquad.GetComponent<SoldierSpawning>().SetSpawnCoords(playerSpawnCoords);//DEPENDENCY_INJECTION
FindObjectOfType<PlayerClickSystem>().SetPlayerSquad(playerSquad);//DEPENDENCY_INJECTION
2022-05-23 14:30:01 +02:00
2022-05-23 14:37:26 +02:00
enemySquad = Instantiate(squadPrefab).GetComponent<Squad>();
enemySquad.gameObject.name = "Enemy Squad";
enemySquad.transform.SetParent(transform);
2022-05-23 15:13:48 +02:00
enemySquad.SetOwnTeam(Entity.Team.Enemy);
}
// Update is called once per frame
void Update()
{
2022-05-23 12:57:50 +02:00
Debug.Log("Added initial soldiers to squad");
// add all ally soldiers to squad
var soldiers = FindObjectsOfType<Soldier>();
2022-05-23 15:13:48 +02:00
var squads = new List<Squad>();
squads.Add(playerSquad);
squads.Add(enemySquad);
foreach (var soldier in soldiers)
{
2022-05-23 15:13:48 +02:00
foreach (var squad in squads)
{
2022-05-23 15:13:48 +02:00
if (soldier.GetOwnTeam() == squad.GetOwnTeam())
{
squad.AddSoldierToSquad(soldier);
}
}
2022-05-23 15:13:48 +02:00
enabled = false;
}
}
}