void FixedUpdate() { //reset visibility halo if (isVisible) { halo.GetType().GetProperty("enabled").SetValue(halo, true, null); } else { halo.GetType().GetProperty("enabled").SetValue(halo, false, null); } //handle zombies by changing state float d = distZombieAhead(); if (d > slowingDist) { currState = State.Walking; } else if (d > stopDist) { currState = State.Decelerating; } else { currState = State.Halted; } //execute appropriate state if (currState == State.Walking) { walking(); } else if (currState == State.Decelerating) { decelerating(d); } else { halted(); } //handle rare weird cases where zombie leaves map for no apparent reason if ((transform.position.x > 33 || transform.position.x < 0) || (transform.position.z > 21 || transform.position.z < 0)) { InitializerScript.zombies.Remove(this); bool isClockwise = false; if ((iStart == 0 && iEnd == 3) || (iStart == iEnd + 1)) { isClockwise = false; //counter clockwise } else { isClockwise = true; //clockwise } init.spawnOneZombie(isEasy, isClockwise); Destroy(this.gameObject); } }
void FixedUpdate() { if (isVisible) { halo.GetType().GetProperty("enabled").SetValue(halo, true, null); } else { halo.GetType().GetProperty("enabled").SetValue(halo, false, null); } //randomly change speed if (Time.time > speedChangeTime) { //randomly select between 2v and v/2 currSpeed = Random.Range((maxSpeed / 4.0f), maxSpeed); speedChangeTime = Time.time + speedChangeDelay; } //randomly change lane if (Random.value < laneChangeP && Time.time > laneChangeTime) { laneChangeTime = Time.time + laneChangeDelay; changeLane(); } //randomly change direction if (Random.value < directionChangeP && Time.time > directionChangeTime) { directionChangeTime = Time.time + directionChangeDelay; //switching direction int t = iEnd; iEnd = iStart; iStart = t; Vector3 v = end; end = start; start = v; direction = -direction; } //handle zombie stopping randomly if (Random.value < stopP && Time.time > stopTime) { //zombie randomely stops stopDuration = Random.Range(0.5f, 3.0f); stopTime = Time.time + stopDelay + stopDuration; currState = State.Halted; halted(); } else if (Time.time < stopTime - stopDelay) { //we still in stop delay, we halt currState = State.Halted; halted(); } else { float d = distZombieAhead(); if (d > slowingDist) { currState = State.Walking; } else if (d > stopDist) { currState = State.Decelerating; } else { currState = State.Halted; } //execute appropriate state if (Time.time > laneChangeTime) { laneChangeTime = Time.time + laneChangeDelay; if (currState == State.Walking) { walking(); } else if (currState == State.Decelerating) { changeLane(); } else { changeLane(); } } else { if (currState == State.Walking) { walking(); } else if (currState == State.Decelerating) { decelerating(d); } else { halted(); } } } //handle rare weird cases where zombie leaves map if ((transform.position.x > 33 || transform.position.x < 0) || (transform.position.z > 21 || transform.position.z < 0)) { InitializerScript.zombies.Remove(this); bool isClockwise = false; if ((iStart == 0 && iEnd == 3) || (iStart == iEnd + 1)) { isClockwise = false; //counter clockwise } else { isClockwise = true; //clockwise } init.spawnOneZombie(isEasy, isClockwise); Destroy(this.gameObject); } }