void FixedUpdate() { if(task != null) { taskPos = task.concernedTile.tileObject.transform.position; taskPos.z = transform.position.z; } if(task != null && Vector3.Distance(transform.position, taskPos) > 1.0f) { transform.position = Vector3.MoveTowards(transform.position, taskPos, 0.5f); }else if (task != null && workProgress < 100) { workProgress++; }else if(workProgress == 100 && task != null) { if(task.type == Workers.TaskType.Dig) { map.map[task.concernedTile.x, task.concernedTile.y].type = 0; task.concernedTile.tileObject.GetComponent<SpriteRenderer>().sprite = testSprite; task.concernedTile.tileObject.layer = 9; Destroy(task.concernedTile.tileObject.GetComponent<BoxCollider2D>()); grid.Scan(); }else if(task.type == Workers.TaskType.BuildHatchery) { GameObject summoning = Instantiate(map.summoningAltarPrefab); summoning.transform.SetParent(map.map[task.concernedTile.x, task.concernedTile.y].tileObject.transform); summoning.transform.localPosition = new Vector3(0, 0, 0); }else if(task.type == Workers.TaskType.BuildTrainingField) { GameObject trainingField = Instantiate(map.trainingFieldPrefab); trainingField.transform.SetParent(map.map[task.concernedTile.x, task.concernedTile.y].tileObject.transform); trainingField.transform.localPosition = new Vector3(0, 0, 0); }else if(task.type == Workers.TaskType.BuildGoldMine) { GameObject goldMine = Instantiate(map.goldMinePrefab); goldMine.transform.SetParent(map.map[task.concernedTile.x, task.concernedTile.y].tileObject.transform); goldMine.transform.localPosition = new Vector3(0, 0, 0); }else if(task.type == Workers.TaskType.BuildMessHall) { GameObject messHall = Instantiate(map.messHallPrefab); messHall.transform.SetParent(map.map[task.concernedTile.x, task.concernedTile.y].tileObject.transform); messHall.transform.localPosition = new Vector3(0, 0, 0); armyScript.forceLimit += 9; armyScript.messHall = messHall; } workProgress = 0; workerManagement.workerList[workerManagement.workerList.IndexOf(workerManagement.testWorker)].currentTask = null; task = null; }else if(task == null) { transform.position = Vector3.MoveTowards(transform.position, new Vector3(0, 0, transform.position.z), 0.5f); } }
void Update() { x = Mathf.FloorToInt (GetComponent<Camera> ().ScreenToWorldPoint (Input.mousePosition).x + 0.5f); y = Mathf.FloorToInt (GetComponent<Camera> ().ScreenToWorldPoint (Input.mousePosition).y + 0.5f); tileText.text = "Current position : <" + x + ", " + y + ">"; if (Input.GetMouseButtonUp (0) && activeTool == PlayerTool.Dig && map.map [x + map.width / 2, y + map.height / 2].type == 1) { if (resourceScript.gold >= resourceScript.digCost) { Workers.Task digTask = new Workers.Task (Workers.TaskType.Dig, map.map [x + map.width / 2, y + map.height / 2]); if (!workerManagement.taskQueue.Contains (digTask)) { workerManagement.taskQueue.Add (digTask); resourceScript.gold -= resourceScript.digCost; } } } else if (Input.GetMouseButtonUp (0) && activeTool == PlayerTool.Hatchery && map.map [x + map.width / 2, y + map.height / 2].type == 0 && map.map [x + map.width / 2, y + map.height / 2].tileObject.transform.childCount == 0) { if (resourceScript.gold >= resourceScript.summoningAltarCost) { Workers.Task summoningAltarTask = new Workers.Task (Workers.TaskType.BuildHatchery, map.map [x + map.width / 2, y + map.height / 2]); if (!workerManagement.taskQueue.Contains (summoningAltarTask)) { workerManagement.taskQueue.Add (summoningAltarTask); resourceScript.gold -= resourceScript.summoningAltarCost; } } } else if (Input.GetMouseButtonUp (0) && activeTool == PlayerTool.GoldMine && map.map [x + map.width / 2, y + map.height / 2].type == 0 && map.map [x + map.width / 2, y + map.height / 2].tileObject.transform.childCount == 0) { if (resourceScript.gold >= resourceScript.goldMineCost) { Workers.Task goldMineTask = new Workers.Task (Workers.TaskType.BuildGoldMine, map.map [x + map.width / 2, y + map.height / 2]); if (!workerManagement.taskQueue.Contains (goldMineTask)) { workerManagement.taskQueue.Add (goldMineTask); resourceScript.gold -= resourceScript.goldMineCost; } } } else if (Input.GetMouseButtonUp (0) && activeTool == PlayerTool.TrainingField && map.map [x + map.width / 2, y + map.height / 2].type == 0 && map.map [x + map.width / 2, y + map.height / 2].tileObject.transform.childCount == 0) { if (resourceScript.gold >= resourceScript.trainingFieldCost) { Workers.Task trainingFieldTask = new Workers.Task (Workers.TaskType.BuildTrainingField, map.map [x + map.width / 2, y + map.height / 2]); if (!workerManagement.taskQueue.Contains (trainingFieldTask)) { workerManagement.taskQueue.Add (trainingFieldTask); resourceScript.gold -= resourceScript.trainingFieldCost; } } }else if (Input.GetMouseButtonUp (0) && activeTool == PlayerTool.MessHall && map.map [x + map.width / 2, y + map.height / 2].type == 0 && map.map [x + map.width / 2, y + map.height / 2].tileObject.transform.childCount == 0) { if (resourceScript.gold >= resourceScript.messHallCost) { Workers.Task messHallTask = new Workers.Task (Workers.TaskType.BuildMessHall, map.map [x + map.width / 2, y + map.height / 2]); if (!workerManagement.taskQueue.Contains (messHallTask)) { workerManagement.taskQueue.Add (messHallTask); resourceScript.gold -= resourceScript.messHallCost; } } }else if(activeTool == PlayerTool.MoveTroops && Input.GetMouseButtonUp(0)) { if(selectedUnit == null) { selectUnit(); }else{ moveUnit(); } } else if(Input.GetMouseButtonUp(0) && activeTool == PlayerTool.Select) { if(map.map [x + map.width / 2, y + map.height / 2].tileObject.transform.childCount > 0 && map.map [x + map.width / 2, y + map.height / 2].tileObject.transform.GetChild(0).name == "Hatchery(Clone)") { if(summoningUIPanel.activeSelf) { selected = null; summoningUIPanel.SetActive(false); upgradeUIPanel.SetActive(false); }else if(!summoningUIPanel.activeSelf) { selected = map.map [x + map.width / 2, y + map.height / 2].tileObject; summoningUIPanel.SetActive(true); upgradeUIPanel.SetActive(true); } }else if(map.map [x + map.width / 2, y + map.height / 2].tileObject.transform.childCount > 0 && map.map [x + map.width / 2, y + map.height / 2].tileObject.transform.GetChild(0).name == "TrainingField(Clone)") { if(trainingUIPanel.activeSelf) { selected = null; trainingUIPanel.SetActive(false); upgradeUIPanel.SetActive(false); }else if(!trainingUIPanel.activeSelf && trainingUIPanel.GetComponent<TrainingFieldUI>().selectedButton != trainingUIPanel.GetComponent<TrainingFieldUI>().trainHeroButton) { selected = map.map [x + map.width / 2, y + map.height / 2].tileObject; trainingUIPanel.SetActive(true); trainingUIPanel.GetComponent<TrainingFieldUI>().trainingField = selected; // upgradeUIPanel.SetActive(true); } }else if(map.map [x + map.width / 2, y + map.height / 2].tileObject.transform.childCount > 0 && map.map [x + map.width / 2, y + map.height / 2].tileObject.transform.GetChild(0).name == "GoldMine(Clone)") { if(summoningUIPanel.activeSelf) { summoningUIPanel.SetActive(false); } if(upgradeUIPanel.activeSelf && selected.transform.GetChild(0).name == "Hatchery(Clone)") { selected = map.map [x + map.width / 2, y + map.height / 2].tileObject; upgradeUIPanel.SetActive(true); }else if(upgradeUIPanel.activeSelf && selected.transform.GetChild(0).name == "GoldMine(Clone)") { selected = map.map [x + map.width / 2, y + map.height / 2].tileObject; selected = null; upgradeUIPanel.SetActive(false); }else if(upgradeUIPanel.activeSelf && selected.transform.GetChild(0).name == "GoldMine(Clone)") { selected = map.map [x + map.width / 2, y + map.height / 2].tileObject; selected = null; upgradeUIPanel.SetActive(false); }else if(upgradeUIPanel.activeSelf && selected == null) { upgradeUIPanel.SetActive(false); }else if(!upgradeUIPanel.activeSelf) { selected = map.map [x + map.width / 2, y + map.height / 2].tileObject; summoningUIPanel.SetActive(false); upgradeUIPanel.SetActive(true); } } } if (Input.GetKeyUp (KeyCode.Alpha2)) { activeTool = PlayerTool.Dig; if(summoningUIPanel.activeSelf) { summoningUIPanel.SetActive(false); selected = null; } if(upgradeUIPanel.activeSelf) { upgradeUIPanel.SetActive(false); selected = null; } if(trainingUIPanel.activeSelf) { trainingUIPanel.SetActive(false); selected = null; } } else if (Input.GetKeyUp (KeyCode.Alpha3)) { activeTool = PlayerTool.Hatchery; if(summoningUIPanel.activeSelf) { summoningUIPanel.SetActive(false); selected = null; } if(upgradeUIPanel.activeSelf) { upgradeUIPanel.SetActive(false); selected = null; } if(trainingUIPanel.activeSelf) { trainingUIPanel.SetActive(false); selected = null; } } else if (Input.GetKeyUp (KeyCode.Alpha4)) { activeTool = PlayerTool.GoldMine; if(summoningUIPanel.activeSelf) { summoningUIPanel.SetActive(false); selected = null; } if(upgradeUIPanel.activeSelf) { upgradeUIPanel.SetActive(false); selected = null; } if(trainingUIPanel.activeSelf) { trainingUIPanel.SetActive(false); selected = null; } } else if (Input.GetKeyUp (KeyCode.Alpha6)) { activeTool = PlayerTool.TrainingField; if(summoningUIPanel.activeSelf) { summoningUIPanel.SetActive(false); selected = null; } if(upgradeUIPanel.activeSelf) { upgradeUIPanel.SetActive(false); selected = null; } if(trainingUIPanel.activeSelf) { trainingUIPanel.SetActive(false); selected = null; } }else if (Input.GetKeyUp (KeyCode.Alpha7)) { activeTool = PlayerTool.MoveTroops; if(summoningUIPanel.activeSelf) { summoningUIPanel.SetActive(false); selected = null; } if(upgradeUIPanel.activeSelf) { upgradeUIPanel.SetActive(false); selected = null; } if(trainingUIPanel.activeSelf) { trainingUIPanel.SetActive(false); selected = null; } }else if (Input.GetKeyUp (KeyCode.Alpha5)) { activeTool = PlayerTool.MessHall; if(summoningUIPanel.activeSelf) { summoningUIPanel.SetActive(false); selected = null; } if(upgradeUIPanel.activeSelf) { upgradeUIPanel.SetActive(false); selected = null; } if(trainingUIPanel.activeSelf) { trainingUIPanel.SetActive(false); selected = null; } }else if (Input.GetKeyUp (KeyCode.Alpha1)) { activeTool = PlayerTool.Select; } if(Input.GetKeyUp(KeyCode.Escape)) { if(summoningUIPanel.activeSelf) { summoningUIPanel.SetActive(false); selected = null; } if(upgradeUIPanel.activeSelf) { upgradeUIPanel.SetActive(false); selected = null; } if(trainingUIPanel.activeSelf) { trainingUIPanel.SetActive(false); selected = null; } } switch(activeTool) { case PlayerTool.Dig: ActiveToolText.text = "Current Tool : Dig (10g/tile)"; break; case PlayerTool.Hatchery: ActiveToolText.text = "Current Tool : Summoning Altar (100 g)"; break; case PlayerTool.Select: ActiveToolText.text = "Current Tool : Select"; break; case PlayerTool.MessHall: ActiveToolText.text = "Current Tool : Mess Hall (50 g)"; break; case PlayerTool.GoldMine: ActiveToolText.text = "Current Tool : Gold Mine (150 g)"; break; case PlayerTool.TrainingField: ActiveToolText.text = "Current Tool : Training Field (500 g)"; break; case PlayerTool.MoveTroops: ActiveToolText.text = "Current Tool : Troop Orders"; break; default: ActiveToolText.text = "Current Tool : None"; break; } if(Input.GetKeyUp(KeyCode.H)) { if(helpPanel.activeSelf && tutorialPanel == null) { helpPanel.SetActive(false); }else if(!helpPanel.activeSelf && tutorialPanel == null) { helpPanel.SetActive(true); } } }