// Update is called once per frame void Update() { //move forward transform.position += (speed * Time.smoothDeltaTime) * transform.up; //check boundary collision WorldBound.WorldBoundStatus status = sceneBoundary.ObjectCollideWorldBound(GetComponent <Renderer>().bounds); if (status != WorldBound.WorldBoundStatus.Inside) { //Debug.Log("collided position: " + this.transform.position); Destroy(gameObject); } }
// Update is called once per frame void Update() { //count down death timer and destroy if it reaches zero if (deathDelay != 0) { deathDelay--; if (deathDelay == 0) { Destroy(gameObject); } } #region Movement based on state //update timer and change state updateTimer(); changeState(); if (currentState == EnemyState.Run) //running { //turn away if not delayed by a boundary collision //if (boundaryBumpDelay-- <= 0 && transform.position.x > globalBehavior.WorldMin.x + buffer && // transform.position.x < globalBehavior.WorldMax.x - buffer && // transform.position.y > globalBehavior.WorldMin.y + buffer && // transform.position.y < globalBehavior.WorldMax.y - buffer) //{ if (boundaryBumpDelay <= 0 && player != null) { //transform.up = (transform.position - player.transform.position); directionV = (transform.position - player.transform.position).normalized; //debug } //transform.position += (Speed * Time.smoothDeltaTime) * transform.up; transform.position += (Speed * Time.smoothDeltaTime) * directionV; } else if (currentState == EnemyState.Stunned) //stunned still { transform.Rotate(transform.forward, Time.deltaTime * TurnSpeed); } else if (levelManager.Movement) //normal { //transform.position += (Speed * Time.smoothDeltaTime) * transform.up; transform.position += (Speed * Time.smoothDeltaTime) * directionV; } #endregion #region Bump off walls and clamp to world //count down bump off wall delay if (boundaryBumpDelay != 0) { boundaryBumpDelay--; } //check boundary collision WorldBound.WorldBoundStatus status = sceneBoundary.ObjectCollideWorldBound(GetComponent <Renderer>().bounds); if (status != WorldBound.WorldBoundStatus.Inside) { //Debug.Log("collided position: " + this.transform.position); newDirection(); boundaryBumpDelay = DELAY; } //clamp to world sceneBoundary.ClampToWorld(transform, 1.0f); #endregion }