public void UnitDie(GameObject unit) { activeUnits.Remove(unit); TileMouseHandle tile = unit.GetComponentInChildren <Unit>().GetAssignedTile(); if (tile != null) { tile.isOccupied = false; } }
// This will send spawn request to server public void RequestSpawnObject(TileMouseHandle tileMouseHandle) { if (objectIndex != nullObjectIndex && spawnTiles[tileMouseHandle.tileIndex].GetComponent <TileMouseHandle>() == tileMouseHandle) { if (remainingUnitNumber[objectIndex] > 0 && !tileMouseHandle.isOccupied) { // Switch off highlight effect for (int i = 0; i < spawnTiles.Length; i++) { spawnTiles[i].GetComponent <TileMouseHandle>().SwitchHighlight(false); } buttons[objectIndex].GetComponent <ButtonController>().Highlight(false); // Send request to server StartCoroutine(RequestSpawnRoutine(tileMouseHandle.gameObject.name, objectIndex)); objectIndex = nullObjectIndex; ToggleInput(false); } } }
IEnumerator RequestSpawnRoutine(string tileName, int objectIndex) { WWW www = new WWW(url + "SpawnRequest.php?id=" + id + "&roundID=" + roundID + "&side=" + (isAttacker? "attacker" : "defender") + "&tileName=" + tileName + "&index=" + objectIndex); yield return(www); ToggleInput(true); if (www.text == "YES") { TileMouseHandle tileMouseHandle = FindTileByName(tileName).GetComponent <TileMouseHandle>(); GameObject tile = spawnTiles[tileMouseHandle.tileIndex]; GameObject unit = Instantiate(prefabs[objectIndex], tile.transform.position, Quaternion.identity); activeUnits.Add(unit); remainingUnitNumber[objectIndex]--; if (!unit.GetComponentInChildren <Unit>().canMove || unit.GetComponentInChildren <Unit>().speed == 0) { tileMouseHandle.isOccupied = true; unit.GetComponentInChildren <Unit>().SetAssignedTile(tileMouseHandle); } buttons[objectIndex].GetComponent <ButtonController>().Cooldown(); } }
public void SetAssignedTile(TileMouseHandle tile) { assignedTile = tile; }