IEnumerator DeployCoroutine(int unitIndex, GameObject player, int spendingPerUnit, int unitCount, int gridX, int gridY) { for (int i = 0; i < unitCount; i++) { Vector3 deployPosition = GRWInterface.GetGridToRW(gridX, gridY, odin.GetComponent <AStarMap>()); CmdDeployUnit(unitIndex, player, deployPosition, spendingPerUnit); yield return(new WaitForSeconds(0.2f)); //yield return null; } }
public void GetMovingGrid(int _xGrid, int _yGrid) { Vector2 tempTarget = GRWInterface.GetGridToRW(_xGrid, _yGrid, unit.odin.GetComponent <AStarMap>()); if (tempTarget.x == -1f) { //FIX ME PLS Debug.Log("grid full"); } GetMovingRW(tempTarget); }
void CmdExecute(string ISOpCode, string ISUnits, int targetX, int targetY, GameObject player) { if (ISOpCode == "deploy") { GameObject newUnit; Vector3 deployPosition = GRWInterface.GetGridToRW(targetX, targetY, odin.GetComponent <AStarMap>()); if (ISUnits == "marine") { if (player.GetComponent <CommandHub>().resource >= 20) { newUnit = Instantiate(deployableUnits[0], deployPosition, Quaternion.identity); player.GetComponent <CommandHub>().RpcSpendResource(20); } else { errorText.GenerateErrorText(); return; } } else if (ISUnits == "sniper") { if (player.GetComponent <CommandHub>().resource >= 45) { newUnit = Instantiate(deployableUnits[1], deployPosition, Quaternion.identity); player.GetComponent <CommandHub>().RpcSpendResource(45); } else { errorText.GenerateErrorText(); return; } } else if (ISUnits == "spotter") { if (player.GetComponent <CommandHub>().resource >= 15) { newUnit = Instantiate(deployableUnits[2], deployPosition, Quaternion.identity); player.GetComponent <CommandHub>().RpcSpendResource(15); } else { errorText.GenerateErrorText(); return; } } //replace bomber -> explosives else if (ISUnits == "bomber") { if (player.GetComponent <CommandHub>().resource >= 30) { newUnit = Instantiate(deployableUnits[3], deployPosition, Quaternion.identity); player.GetComponent <CommandHub>().RpcSpendResource(30); } else { errorText.GenerateErrorText(); return; } } else { errorText.GenerateErrorText(); return; } newUnit.GetComponent <GCS>().client = client; //NetworkServer.SpawnWithClientAuthority(newUnit, conn); NetworkServer.Spawn(newUnit); } else if (ISOpCode == "move") { ClearDeployedUnitsList(); List <int> unitIDs = ParseISUnits(ISUnits); for (int i = 0; i < unitIDs.Count; i++) { //Debug.Log(deployedUnits[unitIDs[i]].GetComponent<GCS>().moveSpeed); //deployedUnits[unitIDs[i]].GetComponent<GCS>().mover.GetMoving(targetX, targetY); GCS unitCommanded = deployedUnits[unitIDs[i]].GetComponent <GCS>(); unitCommanded.currentCommand = ISOpCode; unitCommanded.gridTarget = new Vector2(targetX, targetY); //unitCommanded.currentTarget = new Vector3(targetX, targetY); //unitCommanded.originalTarget = new Vector3(targetX, targetY); } } else if (ISOpCode == "hold_position") { ClearDeployedUnitsList(); List <int> unitIDs = ParseISUnits(ISUnits); for (int i = 0; i < unitIDs.Count; i++) { //Debug.Log(deployedUnits[unitIDs[i]].GetComponent<GCS>().moveSpeed); //deployedUnits[unitIDs[i]].GetComponent<GCS>().mover.GetMoving(targetX, targetY); GCS unitCommanded = deployedUnits[unitIDs[i]].GetComponent <GCS>(); unitCommanded.currentCommand = ISOpCode; unitCommanded.currentTarget = new Vector3(targetX, targetY); unitCommanded.originalTarget = new Vector3(targetX, targetY); } } else { errorText.GenerateErrorText(); } }