Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. [System.Serializable]
  4. public class PlayerMovement : MonoBehaviour
  5. //1 is up, 2 is down, 3 is left and 4 is right
  6. {
  7. private float horizontalMove = 0f;
  8. private float verticalMove = 0f;
  9. public Animator animator;
  10. public float speed = 0f;
  11. public Animator textBoxAnimator;
  12. public Rigidbody2D player;
  13. public bool bridgeSafe = false;
  14. private bool isMovingUp = false;
  15. bool isMovingDown = false;
  16. bool isMovingRight = false;
  17. bool isMovingLeft = false;
  18.  
  19. // Update is called once per frame
  20. private void Update()
  21.  
  22.  
  23.  
  24. {
  25.  
  26. horizontalMove = Input.GetAxisRaw("Horizontal") * speed * Time.deltaTime;
  27. verticalMove = Input.GetAxisRaw("Vertical") * speed * Time.deltaTime;
  28. //animator.SetFloat("Speed", Mathf.Abs(verticalMove));
  29. if (textBoxAnimator.GetBool("isOpen"))
  30. {
  31. return;
  32.  
  33. }
  34. if (Input.GetKey(KeyCode.W))
  35. {
  36.  
  37. transform.Translate(new Vector3(0f, speed * Time.deltaTime, 0f));
  38. animator.SetBool("isUp", true);
  39. animator.SetBool("isDown", false);
  40. animator.SetBool("isLeft", false);
  41. animator.SetBool("isRight", false);
  42. animator.SetBool("isMoving", true);
  43. isMovingUp = true;
  44. isMovingDown = false;
  45. isMovingLeft = false;
  46. isMovingRight = false;
  47.  
  48. }
  49. if (Input.GetKey(KeyCode.S))
  50. {
  51. transform.Translate(new Vector3(0f, -speed * Time.deltaTime, 0f));
  52. animator.SetBool("isDown", true);
  53. animator.SetBool("isRight", false);
  54. animator.SetBool("isLeft", false);
  55. animator.SetBool("isUp", false);
  56. animator.SetBool("isMoving", true);
  57.  
  58. isMovingUp = false;
  59. isMovingDown = true;
  60. isMovingLeft = false;
  61. isMovingRight = false;
  62.  
  63. }
  64. if (Input.GetKey(KeyCode.A))
  65. {
  66. transform.Translate(new Vector3(-speed * Time.deltaTime, 0f, 0f));
  67.  
  68. animator.SetBool("isLeft", true);
  69. animator.SetBool("isRight", false);
  70. animator.SetBool("isDown", false);
  71. animator.SetBool("isUp", false);
  72. animator.SetBool("isMoving", true);
  73.  
  74. isMovingUp = false;
  75. isMovingDown = false;
  76. isMovingLeft = true;
  77. isMovingRight = false;
  78.  
  79.  
  80.  
  81.  
  82. }
  83. if (Input.GetKey(KeyCode.D))
  84. {
  85. transform.Translate(new Vector3(speed * Time.deltaTime, 0f, 0f));
  86.  
  87.  
  88. animator.SetBool("isRight", true);
  89. animator.SetBool("isLeft", false);
  90. animator.SetBool("isDown", false);
  91. animator.SetBool("isUp", false);
  92. animator.SetBool("isMoving", true);
  93.  
  94. isMovingUp = false;
  95. isMovingDown = false;
  96. isMovingLeft = false;
  97. isMovingRight = true;
  98.  
  99.  
  100.  
  101. }
  102. if (!(Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.A) && Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.D))) {//no input
  103. if (isMovingUp == true) {
  104. animator.SetBool("isMoving", false);
  105. animator.SetBool("isIdleUp", true);
  106.  
  107. }
  108. if (isMovingDown == true) {
  109.  
  110. }
  111. if (isMovingLeft == true) {
  112.  
  113. }
  114. if (isMovingRight == true) {
  115.  
  116.  
  117. }
  118.  
  119.  
  120.  
  121. }
  122.  
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement