merloj: Fixed bug with empty squad

This commit is contained in:
Maciekxdabu 2022-06-10 10:59:49 +02:00
parent 150f828c22
commit 06c13568c1
3 changed files with 19 additions and 1 deletions

View File

@ -78,7 +78,7 @@ MonoBehaviour:
MySquad: {fileID: 0}
rangeAttack: 3
rangeView: 1
damageAttack: 1
damageAttack: 10
speedAttack: 2
lastAttackTick: -1
target: {fileID: 0}

View File

@ -63,6 +63,19 @@ public class Squad : MonoBehaviour
soldiers.RemoveFromList(soldier);
((Soldier)soldier).MySquad = null;
soldier.OnDeath.RemoveListener(RemoveSoldierFromSquad);
if (soldiers.GetCount() == 0)
{
Soldier[] objs = FindObjectsOfType<Soldier>();
foreach (Soldier obj in objs)
{
if (obj != soldier && obj.GetOwnTeam() == ownTeam)
{
AddSoldierToSquad(obj);
}
}
}
}
public void AddSpottedEnemy(Entity enemy)

View File

@ -63,6 +63,11 @@ public class TTLList<T> where T : UnityEngine.Object
return new List<T>(dict.Keys);
}
public int GetCount()
{
return dict.Count;
}
// ---------- private methods
// DEBUG - Changes a view list to see soldiers active in squad in inspector