} // end Start /** Update does: * looks at bullet if its in the trigger * get info from bullet if the bullet is going to get hit * moves if its going to get hit */ private void Update() { if (enemyNearByBool) { Vector3 currentBulletLocation = currentBullet.transform.position; currentBulletLocation.y = transform.position.y; transform.LookAt(currentBulletLocation); BulletColiderDetection currentBulletScript = currentBullet.GetComponent<BulletColiderDetection>(); if (currentBulletScript.goingToHit) { Debug.Log("Bullet is going to hit"); Vector3 moveDirection = Vector3.zero; if (currentBulletScript.bulletImpact == "Forward") { Debug.Log("Bullet is going to hit forward"); if (rightOrLeftCooldown < Time.time) { int direction = Random.Range(0, 2); } if (direction == 0) { Debug.Log("Player is going to move to the right"); moveDirection += transform.right; rightOrLeftCooldown = Time.time + 4; } else { Debug.Log("Player is going to move to the left"); moveDirection += -transform.right; rightOrLeftCooldown = Time.time + 4; } } else { moveDirection += -transform.forward; } transform.position += moveDirection.normalized * speed * Time.deltaTime; } // end if bullet is going to hit } // end if enemyNearByBool } // end updatat
} // end Start /** Update does: * looks at bullet if its in the trigger * get info from bullet if the bullet is going to get hit * moves if its going to get hit */ private void Update() { movingForward = false; movingBackward = false; movingLeft = false; movingRight = false; if (playerNearByBool) { Vector3 playerLocation = currentPlayer.transform.position; playerLocation.y = transform.position.y; transform.LookAt(playerLocation); distanceToPlayer = Vector3.Distance(playerLocation, transform.position); if (Vector3.Distance(playerLocation, transform.position) < 5) { transform.position += -transform.forward * speed * Time.deltaTime; movingBackward = true; } else if (Vector3.Distance(playerLocation, transform.position) > 6F && Vector3.Distance(playerLocation, transform.position) < 15) { transform.position += transform.forward * speed * Time.deltaTime; movingForward = true; } } else if (enemyNearByBool) { Vector3 currentBulletLocation = currentBullet.transform.position; currentBulletLocation.y = transform.position.y; transform.LookAt(currentBulletLocation); BulletColiderDetection currentBulletScript = currentBullet.GetComponent<BulletColiderDetection>(); if (currentBulletScript.goingToHit) { //Debug.Log("Bullet is going to hit"); Vector3 moveDirection = Vector3.zero; if (currentBulletScript.bulletImpact == "Forward") { //Debug.Log("Bullet is going to hit forward"); if (rightOrLeftCooldown < Time.time) { int direction = Random.Range(0, 2); } if (direction == 0) { //Debug.Log("Player is going to move to the right"); moveDirection += transform.right; rightOrLeftCooldown = Time.time + 4; movingRight = true; } else { //Debug.Log("Player is going to move to the left"); moveDirection += -transform.right; rightOrLeftCooldown = Time.time + 4; movingLeft = true; } } else { moveDirection += -transform.forward; movingBackward = true; } transform.position += moveDirection.normalized * speed * Time.deltaTime; } // end if bullet is going to hit } // end if enemyNearByBool else if (patrol) { if (currentPoint == null) { currentPoint = patrolPoints[Random.Range(0, patrolPoints.Length)]; } else { transform.LookAt(currentPoint.transform); movingForward = true; transform.position += transform.forward * speed * Time.deltaTime; if (Vector3.Distance(currentPoint.transform.position, transform.position) < 2) { currentPoint = null; } } } if (movingForward) { if (!enemyAnimator.GetBool("Moving_ForwardBool")) { enemyAnimator.SetTrigger("Moving_Forward"); } enemyAnimator.SetBool("Moving_ForwardBool", true); } else if (movingBackward) { if (!enemyAnimator.GetBool("Moving_BackBool")) { enemyAnimator.SetTrigger("Moving_Back"); } enemyAnimator.SetBool("Moving_BackBool", true); } else if (movingLeft) { if (!enemyAnimator.GetBool("Moving_LeftBool")) { enemyAnimator.SetTrigger("Moving_Left"); } enemyAnimator.SetBool("Moving_LeftBool", true); } else if (movingRight) { if (!enemyAnimator.GetBool("Moving_RightBool")) { enemyAnimator.SetTrigger("Moving_Right"); } enemyAnimator.SetBool("Moving_RightBool", true); } else { ResetAnimationBools(); enemyAnimator.SetBool("Looking_Around", true); } if (shootLazer) { if (lazerEyeCooldownTime < Time.deltaTime) { lazerEyeCooldownTime = Time.deltaTime + 4F; } } else { shootLazer = false; } } // end updatat