private IEnumerator Aim() { while (gameObject.activeInHierarchy) { yield return(new WaitForSeconds(5)); IEnumerable <CityScript> livingCitiesInLevel = m_levelSpawned.GetComponentsInChildren <CityScript>().Where(city => !city.isDead); foreach (CityScript target in livingCitiesInLevel) { Ray ray = new Ray(transform.position, m_target.transform.position - transform.position); Debug.DrawRay(transform.position, m_target.transform.position - transform.position); RaycastHit info; if (Physics.Raycast(ray, out info)) { m_target = target; turretTarget = target.transform.position + new Vector3(0.5f, 0.5f, 0.5f); break; } } yield return(new WaitForSeconds(1)); StartCoroutine(FireRound()); } }
// Update is called once per frame void Update() { if (m_target && m_target.isDead) { m_target = GetRandomTarget(); } Tick(); }
// Use this for initialization void Start() { CityCor = NearestCity(); City = CityCor.GetComponent <CityScript>(); Destionaton = City.Destination; sr.color = City.GiveColor(); color = sr.color; DestScript = Destionaton.GetComponent <MapObject>(); }
// void OnTriggerStay(Collider col) // { // if (col.gameObject.tag == "city" ) // { // Debug.Log("TriggerStayColided!"); // Debug.Log("City on range"); // cityOnRange=true; // } // } void OnTriggerExit(Collider col) { if (col.gameObject.tag == "city" ) { Debug.Log("City on range"); cityOnRange=false; city = null; } if (col.gameObject.tag == "digSpot" ) { this.canDig=false; } }
private void OnEnable() { if (m_levelSpawned == null) { gameObject.SetActive(false); return; } m_target = GetRandomTarget(); if (m_target != null) { SetDestinationNear(m_target.transform.position + new Vector3(0.5f, 0.5f, 0.5f), 5.0f); StartCoroutine(Aim()); } }
void OnTriggerEnter(Collider col) { Debug.Log("Colided!"); if (col.gameObject.tag == "city" ) { closecity=col.gameObject; city = closecity.GetComponent<CityScript>(); Debug.Log("City on range"); cityOnRange=true; } if (col.gameObject.tag == "digSpot" ) { this.canDig=true; Debug.Log("GigspotOnRange"); } }
bool NearestEnemy(out GameObject nearestEnemy, out bool DestinationIsCity) { DestinationIsCity = true; float dist = 100f; GameObject newTer = null; GameObject[] allCitys = GameObject.FindGameObjectsWithTag("City"); GameObject[] allFlags = GameObject.FindGameObjectsWithTag("Flag"); foreach (GameObject g in allCitys) { CityScript scr = g.GetComponent <CityScript>(); if (dist > Vector3.Distance(g.transform.position, this.transform.position) && g != this.gameObject && g.transform.parent != this.transform.parent) { dist = Vector3.Distance(g.transform.position, this.transform.position); newTer = g; DestinationIsCity = true; } } foreach (GameObject g in allFlags) { FlagScript scr = g.GetComponent <FlagScript>(); if (dist > Vector3.Distance(g.transform.position, this.transform.position) && scr.CityCor.transform.parent != this.transform.parent) { dist = Vector3.Distance(g.transform.position, this.transform.position); newTer = g; DestinationIsCity = false; } } if (newTer == null) { nearestEnemy = null; } else { nearestEnemy = newTer; return(true); } return(false); }
public void Start() { cityGUI.gui = this; //--TESTING-------- Inventory inv = Game.GlobalInventory; inv.AddItem(new ResourceItem("wood", 100)); inv.AddItem(new ResourceItem("food", 150)); inv.AddItem(new ResourceItem("stone", 25)); //inv.AddItem(new ResourceItem("steel", 100)); capitalScript = CityScript.Create("Test", new Vector3(-1, 0, 0), this); capital = capitalScript.city; //capital.inv = inv; Game.PlaceStarterTileImprovements(capital); Game.SpawnStarterHeroes(); }
/** * Remove all disease cubes of cured disease in a given city. * Use this helper method for movement actions (Medic power). */ private void treatDiseasesByMedicMovement(GameObject city) { CityScript cityScript = city.GetComponent <CityScript> (); GameObject[] diseaseList = GameObject.FindGameObjectsWithTag("Disease"); foreach (GameObject disease in diseaseList) { DiseaseScript diseaseScript = disease.GetComponent <DiseaseScript> (); DiseaseColour colour = diseaseScript.getColour(); if (diseaseScript.getCured()) { int numCubesRemoved = cityScript.removeAllCubes(colour); diseaseScript.removeCubes(numCubesRemoved); // check for eradication if (diseaseScript.getCubesOnBoard() == 0) { diseaseScript.setEradicated(true); } } } }
public void RpcTreatDisease(GameObject player, GameObject disease) { PlayerScript playerScript = player.GetComponent <PlayerScript> (); Role role = playerScript.getRole().getRoleName(); CityScript cityScript = playerScript.getCurrentCity().GetComponent <CityScript> (); DiseaseScript diseaseScript = disease.GetComponent <DiseaseScript> (); DiseaseColour colour = diseaseScript.getColour(); if (diseaseScript.getCured()) { // remove all cubes of the chosen disease int numCubesRemoved = cityScript.removeAllCubes(colour); diseaseScript.removeCubes(numCubesRemoved); // check for eradication if (diseaseScript.getCubesOnBoard() == 0) { diseaseScript.setEradicated(true); } } else if (role == Role.Medic) { // remove all cubes of the chosen disease int numCubesRemoved = cityScript.removeAllCubes(colour); diseaseScript.removeCubes(numCubesRemoved); } else { cityScript.decrementCubeCount(colour); diseaseScript.removeCubes(1); } playerScript.decrementActionsLeft(); }
// Start is called before the first frame update void Start() { instance = this; StartCoroutine(City()); }
// Use this for initialization void Start() { city = GetComponent <CityScript>(); }
public void AddTileToCollection(CityScript city) { Cities.Add(city); }
// Update is called once per frame void Update() { if (StartEmpire != this.transform.parent.parent.gameObject) { City.war = UnityEngine.Random.Range(0, 1) == 1 ? true : false; City.CityIsBisy = false; DestroyObject(this.gameObject); } if (DestinationIsCity) { if (StartEmpire == Destination.transform.parent.gameObject) { City.war = UnityEngine.Random.Range(0, 1) == 1 ? true : false; City.CityIsBisy = false; City.army += this.UnitsCount; DestroyObject(this.gameObject); } } else if (StartEmpire == Destination.transform.parent.parent.gameObject) { City.war = UnityEngine.Random.Range(0, 1) == 1 ? true : false; City.CityIsBisy = false; City.army += this.UnitsCount; DestroyObject(this.gameObject); } if (!OnPosition) { if (Vector3.Distance(this.transform.position, Destination.transform.position) > 0.01f) { Move(); } else { OnPosition = true; if (DestinationIsCity) { CityScript cs = Destination.GetComponent <CityScript>(); float thisPower = UnitsCount * progressLevel * 0.25f + UnitsCount; float EnemyPower = (cs.army * cs.progressLevel * 0.25f + cs.army) + (cs.population * cs.progressLevel * 0.125f + cs.population * 0.5f); if (thisPower > EnemyPower) { cs.transform.parent = this.transform.parent.parent; cs.TakeColor(this.color); cs.population = 0; cs.EmpireColor = (this.color); cs.army = Convert.ToInt32((thisPower - EnemyPower) / 1.25f); City.war = UnityEngine.Random.Range(0, 1) == 1 ? true : false; City.CityIsBisy = false; DestroyObject(this.gameObject); } else { cs.population = Convert.ToInt32((EnemyPower - thisPower) / 1.625f); cs.army = 0; City.war = UnityEngine.Random.Range(0, 1) == 1 ? true : false; City.CityIsBisy = false; DestroyObject(this.gameObject); } } else { FlagScript cs = Destination.GetComponent <FlagScript>(); float thisPower = UnitsCount * progressLevel * 0.25f + UnitsCount; float EnemyPower = (cs.army * cs.progressLevel * 0.25f + cs.army) + (cs.population * cs.progressLevel * 0.125f + cs.population * 0.5f); if (thisPower > EnemyPower) { cs.transform.parent = this.transform.parent.parent; cs.CityCor = this.transform.parent.gameObject; cs.TakeColor(this.color); cs.population = 0; cs.color = this.color; cs.army = Convert.ToInt32((thisPower - EnemyPower) / 1.25f); City.war = UnityEngine.Random.Range(0, 1) == 1 ? true : false; City.CityIsBisy = false; DestroyObject(this.gameObject); } else { cs.population = Convert.ToInt32((EnemyPower - thisPower) / 1.625f); cs.army = 0; City.war = UnityEngine.Random.Range(0, 1) == 1 ? true : false; City.CityIsBisy = false; DestroyObject(this.gameObject); } } } } }