// Update is called once per frame public override void Update() { if (Time.timeScale == 0 || currentState == EnemyState.Dead) { return; } if (bounderyManager.active) { OnScreen = true; } else { OnScreen = false; } if (aggrovationTimer <= 0 && !isKnockbacked) { currentState = EnemyState.Active; } if (!OnScreen) { transform.position = startingPos; currentState = EnemyState.Active; return; } switch (currentState) { case EnemyState.Active: { controller.AddGravity(ref velocity); if (controller.collisions.left || controller.collisions.right) { controller.collisions.faceDirection *= -1; } LineOfSight(); velocity.x = controller.collisions.faceDirection * walkSpeed * Time.deltaTime; controller.Move(velocity); break; } case EnemyState.Knockback: { if (knockbackTimer <= 0 && controller.collisions.below) { // stop knockback isKnockbacked = false; velocity.y = 0; currentState = previousState; } else if (knockbackTimer <= 0 && !controller.collisions.below) { controller.AddGravity(ref velocity); velocity.x = knockbackAmount * knockbackDirection.x * Time.deltaTime; controller.MoveKnockback(velocity); } else { knockbackTimer -= Time.deltaTime; velocity.y = ((knockbackAmount * knockbackDirection.y) / 2) * Time.deltaTime; velocity.x = knockbackAmount * knockbackDirection.x * Time.deltaTime; controller.MoveKnockback(velocity); } break; } case EnemyState.Target: { aggrovationTimer -= Time.deltaTime; switch (enemyType) { case EnemyType.Jumping: { if (!abilityActive) { if (Vector2.Distance(target.transform.position, transform.position) > abilityRange) { controller.AddGravity(ref velocity); if (abilityResetTimer > 0) { abilityResetTimer -= Time.deltaTime; } controller.collisions.faceDirection = (target.transform.position.x >= transform.position.x) ? 1 : -1; velocity.x = controller.collisions.faceDirection * walkSpeed * Time.deltaTime; controller.Move(velocity); } else if (Vector2.Distance(target.transform.position, transform.position) <= abilityRange) { if (abilityResetTimer > 0) { abilityResetTimer -= Time.deltaTime; } else if (abilityResetTimer <= 0) { controller.collisions.faceDirection = (target.transform.position.x >= transform.position.x) ? 1 : -1; abilityActive = true; abilityDurationTimer = abilityDurationTime; } } } else if (abilityActive) { if (abilityDurationTimer > 0) { abilityDurationTimer -= Time.deltaTime; velocity.x = controller.collisions.faceDirection * walkSpeed * 2 * Time.deltaTime; velocity.y = jumpVelocity * Time.deltaTime; controller.MoveWithOutEdgeDetection(velocity); } else if (abilityDurationTimer <= 0) { controller.AddGravity(ref velocity); if (!controller.collisions.below) { velocity.x = controller.collisions.faceDirection * walkSpeed * 2 * Time.deltaTime; controller.MoveWithOutEdgeDetection(velocity); } else if (controller.collisions.below) { abilityResetTimer = abilityResetTime; abilityActive = false; } } } break; } case EnemyType.Sprint: { if (!abilityActive) { if (Vector2.Distance(target.transform.position, transform.position) > abilityRange) { controller.AddGravity(ref velocity); if (abilityResetTimer > 0) { abilityResetTimer -= Time.deltaTime; } controller.collisions.faceDirection = (target.transform.position.x >= transform.position.x) ? 1 : -1; velocity.x = controller.collisions.faceDirection * walkSpeed * Time.deltaTime; controller.Move(velocity); } else if (Vector2.Distance(target.transform.position, transform.position) <= abilityRange) { if (abilityResetTimer > 0) { abilityResetTimer -= Time.deltaTime; } else if (abilityResetTimer <= 0) { controller.collisions.faceDirection = (target.transform.position.x >= transform.position.x) ? 1 : -1; abilityActive = true; abilityDurationTimer = abilityDurationTime; } } } else if (abilityActive) { if (abilityDurationTimer > 0) { abilityDurationTimer -= Time.deltaTime; if (Vector2.Distance(target.transform.position, transform.position) > .1f) { if (abilityDurationTimer <= .2f) { abilityResetTimer = abilityResetTime; abilityActive = false; } controller.AddGravity(ref velocity); velocity.x = controller.collisions.faceDirection * walkSpeed * 2f * Time.deltaTime; controller.Move(velocity); } else if (Vector2.Distance(target.transform.position, transform.position) <= .1f) { if (abilityDurationTimer > .2f) { abilityDurationTimer = .2f; } controller.AddGravity(ref velocity); velocity.x = controller.collisions.faceDirection * walkSpeed * 2f * Time.deltaTime; controller.Move(velocity); } } else if (abilityDurationTimer <= 0) { abilityResetTimer = abilityResetTime; abilityActive = false; } } break; } } break; } case EnemyState.Dead: { break; } case EnemyState.Cutsceen: { break; } } }