void SendArmy(GameObject Destination2, bool DestinationIsCity) { int Sarmy = gold; gold = 0; if (population > recources) { Sarmy += recources; recources = 0; population -= recources; } else { Sarmy += population; population = 0; recources -= population; } CityIsBisy = true; GameObject army = Instantiate(ArmyPrefab, this.transform.position, Quaternion.identity) as GameObject; army.transform.parent = this.transform; ArmyScript armyScript = army.GetComponent <ArmyScript>(); armyScript.City = this.gameObject.GetComponent <CityScript>(); armyScript.Destination = Destination2; armyScript.color = GiveColor(); armyScript.progressLevel = this.progressLevel; armyScript.UnitsCount = Sarmy; armyScript.DestinationIsCity = DestinationIsCity; SpriteRenderer sr = army.GetComponent <SpriteRenderer>(); sr.color = GiveColor(); this.army = 0; CityIsBisy = true; }
private void ConductInteractionWithUnit(GameObject unitCollider) { if (!unitCollider.tag.Equals("Unit")) { return; } ArmyScript unitScript = unitCollider.GetComponent <ArmyScript>(); if (unitScript.GetOwner().Equals(this.owner) && unitScript.ShouldIgnore()) { baseUI.AddArmyBased(unitCollider); Destroy(unitCollider); } else if (!unitScript.GetOwner().Equals(this.owner)) { switch (unitScript.GetOwner()) { case 0: this.GetComponent <SpriteRenderer>().sprite = territoryPrefabs[0]; break; case 1: this.GetComponent <SpriteRenderer>().sprite = territoryPrefabs[1]; break; case 2: this.GetComponent <SpriteRenderer>().sprite = territoryPrefabs[2]; break; } ConductInteractionWithUnit(unitCollider); } }
void FindAllArmyS() { GameObject[] Armys = GameObject.FindGameObjectsWithTag("Army"); foreach (GameObject g in Armys) { ArmyScript ass = g.GetComponent <ArmyScript>(); if (ass.color == this.EmpireColor) { DestroyObject(g); } } }
private void CleanSelectedItem() { if ((Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) && !onItem) { if (curBaseScript) { curBaseScript.CloseBaseMenu(); curBaseScript.SetSelected(false); } if (currentArmyScript) { currentArmyScript.SetSelected(false); } selectedItem = null; curBaseScript = null; currentArmyScript = null; } }
private void MoveUnitFromBase() { if (Input.GetMouseButton(1)) { if (Input.GetMouseButtonDown(1) && !armyGuide && onItem) { armyGuide = Instantiate(armyGuidePref, GetMousePos(), Quaternion.identity); armyGuide.name = "Army Guide"; startSending = true; } else if (armyGuide) { armyGuide.transform.position = GetMousePos(); Debug.Log("SelectedItem: " + selectedItem); } } if (Input.GetMouseButtonUp(1) && startSending) { if (curBaseScript && Vector2.Distance(GetMousePos(), selectedItem.transform.position) > 0.64f) { curBaseScript.SendArmy(GetMousePos()); curBaseScript = null; startSending = false; Debug.Log("Sending From Base."); } else if (currentArmyScript && Vector2.Distance(GetMousePos(), selectedItem.transform.position) > 0.21f) { currentArmyScript.SetArmyDestination(GetMousePos()); currentArmyScript = null; startSending = false; } else { Debug.Log("Not your base!"); } CleanSelectedItem(); Destroy(armyGuide.gameObject); } }
private void SelectItemPlayerOn() { if ((Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) && onItem) { if (itemOn.tag.Equals("Base") && itemOn.GetComponent <BaseScript>().GetOwner() == owner) { curBaseScript = itemOn.GetComponent <BaseScript>(); curBaseScript.SetSelected(onItem); Debug.Log("Select: Base"); } else if (itemOn.tag.Equals("Unit") && itemOn.GetComponent <ArmyScript>().GetOwner() == owner) { currentArmyScript = itemOn.GetComponent <ArmyScript>(); currentArmyScript.SetSelected(onItem); Debug.Log("Select: Army"); } selectedItem = itemOn; } }
public void FindScript() { Component tempScript = currentObjects[globalIndex].GetComponent(typeof(MonoBehaviour)); if (tempScript.GetType().Equals(typeof(TerroristScript))) { TerroristScript tempTerrorist = (TerroristScript)currentObjects[globalIndex].GetComponent(typeof(TerroristScript)); tempTerrorist.KillToDeath(); } if (tempScript.GetType().Equals(typeof(JungleCommandoScript))) { JungleCommandoScript tempJungle = (JungleCommandoScript)currentObjects[globalIndex].GetComponent(typeof(JungleCommandoScript)); tempJungle.KillToDeath(); } if (tempScript.GetType().Equals(typeof(ZombieScript))) { ZombieScript tempZombie = (ZombieScript)currentObjects[globalIndex].GetComponent(typeof(ZombieScript)); tempZombie.KillToDeath(); } if (tempScript.GetType().Equals(typeof(LightScript))) { LightScript tempLight = (LightScript)currentObjects[globalIndex].GetComponent(typeof(LightScript)); tempLight.KillToDeath(); } if (tempScript.GetType().Equals(typeof(ArmyScript))) { ArmyScript tempArmy = (ArmyScript)currentObjects[globalIndex].GetComponent(typeof(ArmyScript)); tempArmy.KillToDeath(); } if (tempScript.GetType().Equals(typeof(MissileScript))) { MissileScript tempMissile = (MissileScript)currentObjects[globalIndex].GetComponent(typeof(MissileScript)); tempMissile.KillToDeath(); } Killed(currentObjects[globalIndex]); }