void HireArcher() { if (RM.gold >= archerUC.gold && RM.wood >= archerUC.wood && RM.food >= archerUC.food && RM.iron >= archerUC.iron && RM.steel >= archerUC.steel && RM.skymetal >= archerUC.skymetal && RM.stone >= archerUC.stone && RM.housing < RM.maxHousing) { UI.BarracksTraining(); RM.gold -= archerUC.gold; RM.wood -= archerUC.wood; RM.food -= archerUC.food; RM.iron -= archerUC.iron; RM.steel -= archerUC.steel; RM.skymetal -= archerUC.skymetal; RM.stone -= archerUC.stone; RM.housing += 1; selectedObj = inputScript.selectedObj; barracksScript = selectedObj.GetComponent <BarracksController>(); buildingScript = selectedObj.GetComponent <BuildingController>(); playerAudio.clip = trainArcherAudio; playerAudio.Play(); barracksScript.HireArcher(); } else { UI.noResourcesText.SetActive(true); StartCoroutine(Wait()); } }
public void OnBuildingDestruction(IEntity b) { //DevConsole.AddCommand("building destroyed"); BarracksController destroyed = null; foreach (var bc in barracksControllers) { if (bc.barracks.UUID == b.UUID) { destroyed = bc; } } if (destroyed != null) { foreach (var u in destroyed.army) { u.OnDestruction += OnUnitDeath; } foreach (var u in destroyed.sentArmy) { u.OnDestruction += OnUnitDeath; } if (destroyed.active) { numActive--; } destroyed.Dispose(); barracksControllers.Remove(destroyed); } RTSBuilding bb = b as RTSBuilding; Team.Buildings.Remove(bb); }
// Use this for initialization void Start() { goldSavedText.text = "Gold: " + GlobalVariables.goldSaved; barracksScriptRef = GameObject.Find("barracks").GetComponent <BarracksController>(); }
// Left click controller public void LeftClick() { // Check for all selectable units in the game Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 350)) { if (hit.collider.tag == "Ground" && (!Input.GetKey(KeyCode.LeftShift))) { DeselectUnits(); UI.CloseAllPanels(); } else if (hit.collider.tag == "Enemy Unit" && (!Input.GetKey(KeyCode.LeftShift))) { DeselectUnits(); selectedObj = hit.collider.gameObject; selectedInfo = selectedObj.GetComponent <UnitSelection>(); unitScript = selectedObj.GetComponent <UnitController>(); selectedInfo.selected = true; // OPEN ENEMY PANELS!! // UnitSelection indicators selectedObj.transform.GetChild(2).gameObject.GetComponent <Projector>().material.SetColor("_Color", Color.red); selectedObj.transform.GetChild(2).gameObject.SetActive(true); // unitAudio = selectedObj.GetComponent<AudioSource>(); // unitAudio.clip = unitAudioClip; // unitAudio.Play(); // isSelected = true; UI.EnemySelect(); } else if (hit.collider.tag == "Selectable") { DeselectUnits(); selectedObj = hit.collider.gameObject; if (!selectedObjects.Contains(selectedObj)) { selectedObjects.Add(selectedObj); } else { selectedObjects.Remove(selectedObj); } selectedObj.transform.GetChild(2).gameObject.GetComponent <Projector>().material.SetColor("_Color", Color.green); selectedInfo = selectedObj.GetComponent <UnitSelection>(); unitScript = selectedObj.GetComponent <UnitController>(); if (selectedInfo.selected == true) { DeselectUnits(); } else if (Input.GetKey(KeyCode.LeftShift)) { if (!unitScript.isDead) { selectedInfo.selected = true; // UnitSelection indicators selectedObj.transform.GetChild(2).gameObject.SetActive(true); playerAudio.clip = unitAudioClip; playerAudio.Play(); if (!unitScript.isDead) { isSelected = true; } if (unitScript.unitType == "Worker") { UI.WorkerSelect(); } else if (unitScript.unitType == "Swordsman") { UI.SwordsmanSelect(); } else if (unitScript.unitType == "Archer") { UI.ArcherSelect(); } else if (unitScript.unitType == "Wizard") { UI.WizardSelect(); } else if (unitScript.unitType == "Footman") { UI.FootmanSelect(); } } } else { if (!unitScript.isDead) { GameObject[] selectedIndicators = GameObject.FindGameObjectsWithTag("SelectedIndicator"); for (int j = 0; j < selectedIndicators.Length; j++) { selectedIndicators[j].transform.gameObject.SetActive(false); selectedIndicators[j].transform.parent.GetComponent <UnitSelection>().selected = false; } selectedInfo.selected = true; // UnitSelection indicators selectedObj.transform.GetChild(2).gameObject.SetActive(true); playerAudio.clip = unitAudioClip; playerAudio.Play(); if (!unitScript.isDead) { isSelected = true; } if (unitScript.unitType == "Worker") { UI.WorkerSelect(); } else if (unitScript.unitType == "Swordsman") { UI.SwordsmanSelect(); } else if (unitScript.unitType == "Archer") { UI.ArcherSelect(); } else if (unitScript.unitType == "Wizard") { UI.WizardSelect(); } else if (unitScript.unitType == "Footman") { UI.FootmanSelect(); } } } } else if (hit.collider.tag == "Enemy Unit" || hit.collider.tag == "Player 1" || hit.collider.tag == "Foundation" || hit.collider.tag == "Barracks" || hit.collider.tag == "House" || hit.collider.tag == "Resource" || hit.collider.tag == "Fort" || hit.collider.tag == "Blacksmith" || hit.transform.tag == "Stables") { UI.CloseAllPanels(); if (selectedObjects.Count >= 0) { DeselectUnits(); } selectedObj = hit.collider.gameObject; if (selectedObj.tag == "Player 1") { buildingScript = selectedObj.GetComponent <BuildingController>(); if (buildingScript.unitType == "Lumber Yard") { selectedObj.transform.GetChild(0).gameObject.SetActive(true); UI.LumberYardSelect(); } else if (buildingScript.unitType == "Town Hall") { selectedObj.transform.GetChild(0).gameObject.SetActive(true); townHallScript = selectedObj.GetComponent <TownHallController>(); isTraining = townHallScript.isTraining; SwapProgressIcon(); if (isTraining) { UI.TownHallTraining(); } else { UI.TownHallSelect(); } } } else if (selectedObj.tag == "House") { selectedObj.transform.GetChild(0).gameObject.SetActive(true); UI.HouseSelect(); } else if (selectedObj.tag == "Resource") { selectedObj.transform.GetChild(0).gameObject.SetActive(true); UI.ResourceSelect(); } else if (selectedObj.tag == "Foundation") { selectedObj.transform.GetChild(0).gameObject.SetActive(true); foundationScript = selectedObj.GetComponent <FoundationController>(); isBuilding = foundationScript.isBuilding; if (isBuilding) { SwapProgressIcon(); UI.FoundationBuilding(); } else { UI.FoundationSelect(); } } else if (selectedObj.tag == "Blacksmith") { blacksmithScript = selectedObj.GetComponent <BlacksmithController>(); selectedObj.transform.GetChild(0).gameObject.SetActive(true); isTraining = blacksmithScript.isTraining; SwapProgressIcon(); if (isTraining) { UI.BlacksmithTraining(); } else { UI.BlacksmithSelect(); } } else if (selectedObj.tag == "Barracks") { selectedObj.transform.GetChild(0).gameObject.SetActive(true); barracksScript = selectedObj.GetComponent <BarracksController>(); isTraining = barracksScript.isTraining; SwapProgressIcon(); if (isTraining) { UI.BarracksTraining(); } else { UI.BarracksSelect(); } } else if (selectedObj.tag == "Stables") { selectedObj.transform.GetChild(0).gameObject.SetActive(true); UI.StablesSelect(); } } else if (hit.collider.tag != "Selectable" && (!Input.GetKey(KeyCode.LeftShift))) { DeselectUnits(); UI.CloseAllPanels(); } } }