PlayerController.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using Cinemachine;
  2. using DG.Tweening;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using UnityEngine;
  7. public class PlayerController : EntityBase {
  8. internal override bool isPressingCrouch() => InputM.GetKeyEvent(InputM.KeyType.Crouch);
  9. internal override bool isPressDownJump() => InputM.GetKeyEvent(InputM.KeyType.Jump);
  10. internal override bool isPressingLeft() => InputM.GetKeyEvent(InputM.KeyType.Left);
  11. internal override bool isPressingRight() => InputM.GetKeyEvent(InputM.KeyType.Right);
  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. Camera.current.DOShakePosition(0.3f, 0.3f, 20);
  25. }
  26. // ²âÊÔ·½·¨£º°´ Ctrl+R Éú³É÷»×Ó
  27. public GameObject dice;
  28. private void LateUpdate() {
  29. if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyUp(KeyCode.R)) {
  30. DiceEntity diceNew = GameObject.Instantiate(dice).GetComponent<DiceEntity>();
  31. diceNew.key = Module.RandomOne(InputM.keyTypes.ToList());
  32. }
  33. }
  34. }