mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-04 17:43:12 +02:00
50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
// 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()
|
|
{
|
|
playerSquad = Instantiate(squadPrefab).GetComponent<Squad>();
|
|
playerSquad.gameObject.name = "Player Squad";
|
|
playerSquad.transform.SetParent(transform);
|
|
playerSquad.SetOwnTeam(Entity.Team.Ally);
|
|
playerSquad.gameObject.AddComponent<SoldierSpawning>();
|
|
playerSquad.GetComponent<SoldierSpawning>().SetSpawnCoords(playerSpawnCoords);
|
|
|
|
enemySquad = Instantiate(squadPrefab).GetComponent<Squad>();
|
|
enemySquad.gameObject.name = "Enemy Squad";
|
|
enemySquad.transform.SetParent(transform);
|
|
enemySquad.SetOwnTeam(Entity.Team.Enemy);
|
|
}
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
Debug.Log("Added initial soldiers to squad");
|
|
// add all ally soldiers to squad
|
|
var soldiers = FindObjectsOfType<Soldier>();
|
|
var squads = new List<Squad>();
|
|
squads.Add(playerSquad);
|
|
squads.Add(enemySquad);
|
|
|
|
foreach (var soldier in soldiers)
|
|
{
|
|
foreach (var squad in squads)
|
|
{
|
|
if (soldier.GetOwnTeam() == squad.GetOwnTeam())
|
|
{
|
|
squad.AddSoldierToSquad(soldier);
|
|
}
|
|
}
|
|
enabled = false;
|
|
}
|
|
}
|
|
}
|