mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-04 16:23:11 +02:00
merloj: getallsoldiers()
This commit is contained in:
parent
c5bde051c5
commit
93ff6c93d4
@ -83,6 +83,11 @@ public class TilemapManager : MonoBehaviour
|
||||
|
||||
tiles[x, y].standingSoldier = Instantiate(soldierPrefab, tilemap.CellToWorld(new Vector3Int(x, y, 0)), Quaternion.identity).GetComponent<Soldier>();
|
||||
|
||||
if (isAlly)
|
||||
tiles[x, y].standingSoldier.setOwnTag(Soldier.SoldierType.Ally);
|
||||
else
|
||||
tiles[x, y].standingSoldier.setOwnTag(Soldier.SoldierType.Enemy);
|
||||
|
||||
if (tiles[x, y].standingSoldier != null)
|
||||
return true;
|
||||
|
||||
@ -109,6 +114,19 @@ public class TilemapManager : MonoBehaviour
|
||||
return tiles[x,y].standingSoldier;
|
||||
}
|
||||
|
||||
public Soldier[] GetAllSoldiers()
|
||||
{
|
||||
List<Soldier> list = new List<Soldier>();
|
||||
|
||||
foreach (Tile obj in tiles)
|
||||
{
|
||||
if (obj.standingSoldier != null)
|
||||
list.Add(obj.standingSoldier);
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public bool MoveSoldier(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
if (GetTileState(x1, y1) == TileState.taken && GetTileState(x2, y2) == TileState.free)
|
||||
|
||||
@ -4,7 +4,7 @@ using UnityEngine;
|
||||
|
||||
public class Soldier : MonoBehaviour
|
||||
{
|
||||
private enum SoldierType
|
||||
public enum SoldierType
|
||||
{
|
||||
Ally,
|
||||
Enemy
|
||||
@ -22,15 +22,15 @@ public class Soldier : MonoBehaviour
|
||||
setEnemyTag();
|
||||
}
|
||||
|
||||
public void setOwnTag(string tag)
|
||||
public void setOwnTag(SoldierType type)
|
||||
{
|
||||
ourType = tag;
|
||||
ourType = type;
|
||||
}
|
||||
|
||||
public void setEnemyTag()
|
||||
{
|
||||
if(ourType == "Ally") enemyType = "Enemy";
|
||||
else enemyType = "Ally";
|
||||
if(ourType == SoldierType.Ally) enemyType = SoldierType.Enemy;
|
||||
else enemyType = SoldierType.Ally;
|
||||
}
|
||||
|
||||
void Awake()
|
||||
@ -45,7 +45,7 @@ public class Soldier : MonoBehaviour
|
||||
void UpdateTarget ()
|
||||
{
|
||||
// Enemies are the game objects tagged with the "Enemy"
|
||||
GameObject[] enemies = GameObject.FindGameObjectsWithTag(enemyTag);
|
||||
GameObject[] enemies = GameObject.FindGameObjectsWithTag(enemyType);
|
||||
Debug.Log(enemies.Length);
|
||||
// We have not found enemy yet so the distance to enemy is "infinite"
|
||||
float shortestDistance = Mathf.Infinity;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user