PlayerController.cs 1021 B

1234567891011121314151617181920212223242526272829
  1. using Cinemachine;
  2. using DG.Tweening;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. public class PlayerController : EntityBase {
  7. public string keyLeft = "a", keyRight = "d", keyJump = "w", keyDown = "s";
  8. internal override bool isPressingCrouch() => Input.GetKey(keyDown);
  9. internal override bool isPressingJump() => Input.GetKey(keyJump);
  10. internal override bool isPressingLeft() => Input.GetKey(keyLeft);
  11. internal override bool isPressingRight() => Input.GetKey(keyRight);
  12. internal override void OnHitBorder() {
  13. Hurt();
  14. transform.position = new Vector3(0, 8, 0);
  15. }
  16. public float knockbackForceH = 30f, knockbackForceV = 15f;
  17. internal override void OnHitEnemy(Collision2D collision) {
  18. Hurt();
  19. int face = collision.transform.position.x < transform.position.x ? 1 : -1;
  20. rb.velocity = new Vector2(face * knockbackForceH, knockbackForceV);
  21. }
  22. public void Hurt() {
  23. rb.velocity = Vector2.zero;
  24. }
  25. }