void Logic() { //references to other scripts for time/spawning of food etc GameObject Manage = GameObject.Find("_Manager"); TimerScript timerscript = Manage.GetComponent <TimerScript>(); SpawnBlob spawnfood = Manage.GetComponent <SpawnBlob>(); float time = timerscript.Timer; //if creature still has time and detects food go for food if (time < 50 && fooddetected == true && outofenergy == false) { navMeshAgent.SetDestination(foodposition); fooddetected = false; } // ran out of energy if (energy - distanceTravelled <= 30) { outofenergy = true; } if (outofenergy == true) { navMeshAgent.SetDestination(goHome()); } //go home before time up if (time >= 50) { navMeshAgent.SetDestination(goHome()); //Debug.Log("Home time"); } }
void SpawnEnemy(GameObject enemy) { Vector3 pos = transform.position + new Vector3(Random.Range(-width, width), Random.Range(-height, height), 0); pos.z = pos.y; GameObject newSpawn = Instantiate(spawnBlob, pos, spawnBlob.transform.rotation); SpawnBlob blob = newSpawn.GetComponent <SpawnBlob>(); blob.spawnPrefab = enemy; }
// Update is called once per frame void Update() { //references to other scripts for time/spawning of food etc GameObject Manage = GameObject.Find("_Manager"); TimerScript timerscript = Manage.GetComponent <TimerScript>(); SpawnBlob spawnfood = Manage.GetComponent <SpawnBlob>(); float timetest = timerscript.Timer; //Coroutines if (!inCoroutine) { StartCoroutine(Coroutine()); } if (!testCoroutine) { StartCoroutine(Couroutine2()); } //Ratio for speed (higher speed = more energy consumption speedmultiplier = navMeshAgent.speed / 3.5f; //if creature has a higher speed, make them consume more energy else run as normal if (fasterspeed == true) { distanceTravelled += (Vector3.Distance(transform.position, lastPosition)) * speedmultiplier; } else { distanceTravelled += Vector3.Distance(transform.position, lastPosition); } lastPosition = transform.position; //Try for mutation at end of day, and Reset values if (timetest == 60) { distanceTravelled = 0; foodcount = 0; outofenergy = false; fooddetected = false; if (mutated == false) { Mutate(); mutated = true; } } //if time is up and creature has 2 pieces of food duplicate it if (timetest == 58 && foodcount >= 2 && reproduced == false) { foodcount = 0; Instantiate(Blob, new Vector3(15, 1, 0), transform.rotation); //Debug.Log("i have reproduced"); reproduced = true; } //destroy remaining food and spawn new ones if (timetest == 60 && fooddeleted == false) { GameObject[] allObjects = GameObject.FindGameObjectsWithTag("Food"); foreach (GameObject obj in allObjects) { Destroy(obj); } spawnfood.SpawnFood(); fooddeleted = true; } //reset temp bool if (timetest == 1) { fooddeleted = false; mutated = false; reproduced = false; recordadded = false; hunting = false; } //no food = death if (timetest == 57 && foodcount == 0) { Destroy(Blob); //Debug.Log("I have died"); } //add record to excel spreadsheet if (timetest == 55) { if (recordadded == false) { addtest(navMeshAgent.speed, energy); recordadded = true; } } //creature is too fast, no more mutations if (navMeshAgent.speed > 10) { toofast = true; } //check if creature and food are in same place(to eat it) foodcheck(); }