EnemyHeavy.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class EnemyHeavy : EnemyBase {
  5. internal override bool isPressingCrouch() => false;
  6. internal override bool isPressDownJump() => false;
  7. internal override bool isPressingLeft() => movingLeft;
  8. internal override bool isPressingRight() => !movingLeft;
  9. private float turnCooldown = 0f;
  10. internal override void OnUpdate() {
  11. base.OnUpdate();
  12. if (!isLand) return;
  13. bool shouldTurn =
  14. (movingLeft && Physics2D.Linecast(transform.position, transform.position + Vector3.left * 0.5f, LayerMask.GetMask("Marker"))) ||
  15. (!movingLeft && Physics2D.Linecast(transform.position, transform.position + Vector3.right * 0.5f, LayerMask.GetMask("Marker")));
  16. if (Mathf.Abs(rb.velocity.x) > filpSpeed && (rb.velocity.x > 0 == movingLeft)) shouldTurn = true;
  17. turnCooldown -= Time.deltaTime;
  18. if (shouldTurn && turnCooldown <= 0f) {
  19. movingLeft = !movingLeft;
  20. turnCooldown = 0.6f;
  21. }
  22. }
  23. public float knockbackForceH = 30f, knockbackForceV = 15f;
  24. internal override void OnHitEnemy(Collision2D collision) {
  25. int face = collision.transform.position.x < transform.position.x ? 1 : -1;
  26. rb.velocity = new Vector2(face * knockbackForceH, knockbackForceV);
  27. }
  28. }