mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-06 13:03:16 +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>();
|
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)
|
if (tiles[x, y].standingSoldier != null)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -109,6 +114,19 @@ public class TilemapManager : MonoBehaviour
|
|||||||
return tiles[x,y].standingSoldier;
|
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)
|
public bool MoveSoldier(int x1, int y1, int x2, int y2)
|
||||||
{
|
{
|
||||||
if (GetTileState(x1, y1) == TileState.taken && GetTileState(x2, y2) == TileState.free)
|
if (GetTileState(x1, y1) == TileState.taken && GetTileState(x2, y2) == TileState.free)
|
||||||
|
|||||||
@ -4,7 +4,7 @@ using UnityEngine;
|
|||||||
|
|
||||||
public class Soldier : MonoBehaviour
|
public class Soldier : MonoBehaviour
|
||||||
{
|
{
|
||||||
private enum SoldierType
|
public enum SoldierType
|
||||||
{
|
{
|
||||||
Ally,
|
Ally,
|
||||||
Enemy
|
Enemy
|
||||||
@ -22,15 +22,15 @@ public class Soldier : MonoBehaviour
|
|||||||
setEnemyTag();
|
setEnemyTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOwnTag(string tag)
|
public void setOwnTag(SoldierType type)
|
||||||
{
|
{
|
||||||
ourType = tag;
|
ourType = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEnemyTag()
|
public void setEnemyTag()
|
||||||
{
|
{
|
||||||
if(ourType == "Ally") enemyType = "Enemy";
|
if(ourType == SoldierType.Ally) enemyType = SoldierType.Enemy;
|
||||||
else enemyType = "Ally";
|
else enemyType = SoldierType.Ally;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
@ -45,7 +45,7 @@ public class Soldier : MonoBehaviour
|
|||||||
void UpdateTarget ()
|
void UpdateTarget ()
|
||||||
{
|
{
|
||||||
// Enemies are the game objects tagged with the "Enemy"
|
// Enemies are the game objects tagged with the "Enemy"
|
||||||
GameObject[] enemies = GameObject.FindGameObjectsWithTag(enemyTag);
|
GameObject[] enemies = GameObject.FindGameObjectsWithTag(enemyType);
|
||||||
Debug.Log(enemies.Length);
|
Debug.Log(enemies.Length);
|
||||||
// We have not found enemy yet so the distance to enemy is "infinite"
|
// We have not found enemy yet so the distance to enemy is "infinite"
|
||||||
float shortestDistance = Mathf.Infinity;
|
float shortestDistance = Mathf.Infinity;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user