void SwapProgressIcon() { progressIcon = GameObject.Find("ProgressIcon").GetComponent <Image>(); // UI Functions buildingScript = selectedObj.GetComponent <BuildingController>(); if (buildingScript.unitType == "Town Hall") { progressIcon.sprite = townHallScript.villagerPrefab.GetComponent <UnitController>().unitIcon; } else if (buildingScript.unitType == "Barracks") { if (buildingScript.GetComponent <BarracksController>().unit == "Footman") { progressIcon.sprite = barracksScript.footmanPrefab.GetComponent <UnitController>().unitIcon; } else if (buildingScript.GetComponent <BarracksController>().unit == "Swordsman") { progressIcon.sprite = barracksScript.swordsmanPrefab.GetComponent <UnitController>().unitIcon; } } else if (buildingScript.tag == "Foundation") { foundationScript = selectedObj.GetComponent <FoundationController>(); progressIcon.sprite = foundationScript.buildingPrefab.GetComponent <BuildingController>().icon; } else { progressIcon.sprite = buildingScript.icon; } }
// Allows collider of resources public void OnTriggerEnter(Collider other) { GameObject hitObject = other.gameObject; if (hitObject.tag == "Resource" && hitObject.gameObject == targetNode && gameObject.GetComponent <UnitController>().unitType == "Worker") { isGathering = true; harvestScript = targetNode.GetComponent <NodeManager>(); harvestSpeed = harvestScript.harvestTime; heldResourceType = hitObject.GetComponent <NodeManager>().resourceType; StartCoroutine(Tick()); } else if (hitObject.tag == "Foundation" && hitObject.gameObject == targetNode && gameObject.GetComponent <UnitController>().unitType == "Worker") { isBuilding = true; hitObject.GetComponent <FoundationController>().builders++; buildScript = targetNode.GetComponent <FoundationController>(); buildSpeed = buildScript.buildTime; StartCoroutine(Tick()); } else if (hitObject.tag == "Player 1" && task == ActionList.Delivering && gameObject.GetComponent <UnitController>().unitType == "Worker") { if (heldResourceType == NodeManager.ResourceTypes.Skymetal) { DropSkyMetal(); } if (heldResourceType == NodeManager.ResourceTypes.Wood) { DropWood(); } if (heldResourceType == NodeManager.ResourceTypes.Iron) { DropIron(); } if (heldResourceType == NodeManager.ResourceTypes.Stone) { DropStone(); } if (heldResourceType == NodeManager.ResourceTypes.Gold) { DropGold(); } if (heldResourceType == NodeManager.ResourceTypes.Food) { DropFood(); } } }
// 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(); } } }