EnemyHeavy.cs 992 B

123456789101112131415161718192021222324252627
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class EnemyHeavy : EntityBase {
  5. public bool movingLeft = false;
  6. internal override bool isPressingCrouch() => false;
  7. internal override bool isPressDownJump() => false;
  8. internal override bool isPressingLeft() => movingLeft;
  9. internal override bool isPressingRight() => !movingLeft;
  10. internal override void OnUpdate() {
  11. bool shouldTurn = false;
  12. if (Mathf.Abs(rb.velocity.x) > 0.001f && (rb.velocity.x > 0 == movingLeft)) shouldTurn = true;
  13. if (shouldTurn) movingLeft = !movingLeft;
  14. }
  15. internal override void OnHitBorder() {
  16. Destroy(gameObject);
  17. }
  18. public float knockbackForceH = 30f, knockbackForceV = 15f;
  19. internal override void OnHitEnemy(Collision2D collision) {
  20. int face = collision.transform.position.x < transform.position.x ? 1 : -1;
  21. rb.velocity = new Vector2(face * knockbackForceH, knockbackForceV);
  22. }
  23. }