public void InstantiateUnits(Settings settings, CellManager cellManager) { Units = new GameObject("Units"); player = Object.Instantiate(Resources.Load("Prefabs/Player"), Units.transform) as GameObject; var playerUnit = player.GetComponent <Unit>(); playerUnit.Pos = settings.playerStartPosition; playerUnit.moveController = 1; playerUnit.cellManager = cellManager; playerUnit.settings = settings; playerUnit.speed = settings.playerSpeed; enemyParent = new GameObject("enemies"); enemyParent.transform.SetParent(Units.transform); for (var i = 0; i < settings.enemyCount; i++) { var enemy = Object.Instantiate(Resources.Load("Prefabs/Enemy"), enemyParent.transform) as GameObject; var enemyUnit = enemy.GetComponent <Unit>(); var enemyPos = new Vector2(Random.Range(0, settings.labirintSize), Random.Range(0, settings.labirintSize)); enemyUnit.settings = settings; enemyUnit.Pos = enemyPos; enemyUnit.moveController = 2; enemyUnit.cellManager = cellManager; enemyUnit.target = player.transform; enemyUnit.speed = settings.enemySpeed; } pathFinder = new PathFinder(cellManager); coinParent = new GameObject("Coins"); coinParent.transform.SetParent(Units.transform); for (int i = 0; i < settings.coinCount; i++) { GenerateCoinPosition(4, cellManager); } for (var i = 0; i < cellManager.cells.Length; i++) { if ((cellManager.cells[i] & CellManager.maskCoin) == 0) { continue; } var coin = Object.Instantiate(Resources.Load("Prefabs/Coin"), coinParent.transform) as GameObject; var coinUnit = coin.GetComponent <Unit>(); coin.transform.position = cellManager.GetPositionByCellIndex(i); coinUnit.moveController = 0; coinUnit.cellManager = cellManager; coinUnit.settings = settings; } }
private void CreateWall(CellManager cellManager, int cellIndex, ulong maskWall, Vector3 deltaWallPosition, int rotationY) { if ((cellManager.cells[cellIndex] & maskWall) != 0) { var position = cellManager.GetPositionByCellIndex(cellIndex); var instance = Object.Instantiate(WallGameObject, position + deltaWallPosition, Quaternion.Euler(0, rotationY, 0), walls.transform); if (cellManager.CheckExit(cellIndex, deltaWallPosition)) { instance.GetComponent <MeshRenderer>().material.color = Color.blue; } } }