Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.04 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. public bool hasShield = false;
  16. bool isMovingDown = false;
  17. bool isMovingRight = false;
  18. bool isMovingLeft = false;
  19.  
  20. private AudioSource audioSrc;
  21. private bool isSprinting;
  22. public float walkSpeed;
  23. public float sprintSpeed;
  24. private float xAxis;
  25. private float yAxis;
  26.  
  27. // Update is called once per frame
  28. private void Update()
  29. {
  30. xAxis = Input.GetAxis("Horizontal");//moblie input
  31. yAxis = Input.GetAxis("Vertical");//moblie input
  32.  
  33. /* if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) {
  34. Touch touch = Input.touches[0];
  35. xAxis = touch.deltaPosition.x;
  36. yAxis = touch.deltaPosition.y;
  37.  
  38. }*/
  39. Debug.Log(xAxis);
  40. if (textBoxAnimator.GetBool("textboxOpen"))
  41. {
  42. return;
  43. }
  44.  
  45. if (Input.GetKey(KeyCode.W)|| yAxis>0)//yAxis>0 supposed to be me testing if moving down will play move up animation
  46. {
  47.  
  48. transform.Translate(new Vector3(0f, speed * Time.deltaTime, 0f));
  49. animator.SetBool("isUp", true);
  50. animator.SetBool("isDown", false);
  51. animator.SetBool("isLeft", false);
  52. animator.SetBool("isRight", false);
  53. animator.SetBool("isMoving", true);
  54.  
  55. isMovingUp = true;
  56. isMovingDown = false;
  57. isMovingLeft = false;
  58. isMovingRight = false;
  59.  
  60. if (Input.GetKey(KeyCode.LeftShift))
  61. {
  62. Debug.Log("Sprinting");
  63. transform.Translate(new Vector3(0f, sprintSpeed * Time.deltaTime, 0f));
  64. GetComponent<PlayerMelee>().setSprint(true);
  65.  
  66. }
  67. else
  68. {
  69. GetComponent<PlayerMelee>().setSprint(false);
  70.  
  71.  
  72. }
  73.  
  74.  
  75. }
  76. if (Input.GetKey(KeyCode.S)|| yAxis >0)//yAxis>0 supposed to be me testing if moving down will play move down animation
  77. {
  78. transform.Translate(new Vector3(0f, -speed * Time.deltaTime, 0f));
  79. animator.SetBool("isDown", true);
  80. animator.SetBool("isRight", false);
  81. animator.SetBool("isLeft", false);
  82. animator.SetBool("isUp", false);
  83. animator.SetBool("isMoving", true);
  84.  
  85. isMovingUp = false;
  86. isMovingDown = true;
  87. isMovingLeft = false;
  88. isMovingRight = false;
  89.  
  90. if (Input.GetKey(KeyCode.LeftShift))
  91. {
  92. transform.Translate(new Vector3(0f, -sprintSpeed * Time.deltaTime, 0f));
  93. GetComponent<PlayerMelee>().setSprint(true);
  94.  
  95. }
  96. else
  97. {
  98. GetComponent<PlayerMelee>().setSprint(false);
  99.  
  100. }
  101.  
  102.  
  103.  
  104.  
  105. }
  106. if (Input.GetKey(KeyCode.A))
  107. {
  108. transform.Translate(new Vector3(-speed * Time.deltaTime, 0f, 0f));
  109.  
  110. animator.SetBool("isLeft", true);
  111. animator.SetBool("isRight", false);
  112. animator.SetBool("isDown", false);
  113. animator.SetBool("isUp", false);
  114. animator.SetBool("isMoving", true);
  115.  
  116. isMovingUp = false;
  117. isMovingDown = false;
  118. isMovingLeft = true;
  119. isMovingRight = false;
  120.  
  121. if (Input.GetKey(KeyCode.LeftShift))
  122. {
  123. transform.Translate(new Vector3(-sprintSpeed * Time.deltaTime, 0f, 0f));
  124. GetComponent<PlayerMelee>().setSprint(true);
  125.  
  126. }
  127. else
  128. {
  129.  
  130. GetComponent<PlayerMelee>().setSprint(false);
  131.  
  132. }
  133.  
  134.  
  135.  
  136.  
  137. }
  138. if (Input.GetKey(KeyCode.D))
  139. {
  140. transform.Translate(new Vector3(speed * Time.deltaTime, 0f, 0f));
  141.  
  142.  
  143. animator.SetBool("isRight", true);
  144. animator.SetBool("isLeft", false);
  145. animator.SetBool("isDown", false);
  146. animator.SetBool("isUp", false);
  147. animator.SetBool("isMoving", true);
  148.  
  149. isMovingUp = false;
  150. isMovingDown = false;
  151. isMovingLeft = false;
  152. isMovingRight = true;
  153.  
  154.  
  155. if (Input.GetKey(KeyCode.LeftShift))
  156. {
  157. transform.Translate(new Vector3(sprintSpeed * Time.deltaTime, 0f, 0f));
  158. GetComponent<PlayerMelee>().setSprint(true);
  159.  
  160. }
  161. else
  162. {
  163. GetComponent<PlayerMelee>().setSprint(false);
  164.  
  165.  
  166. }
  167.  
  168.  
  169.  
  170. }
  171.  
  172. if (!Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.D))
  173. {//no input
  174. if (isMovingUp == true)
  175. {
  176. animator.SetBool("isIdleUp", true);
  177. animator.SetBool("isIdleDown", false);
  178. animator.SetBool("isIdleRight", false);
  179. animator.SetBool("isIdleLeft", false);
  180. animator.SetBool("isMoving", false);
  181. animator.SetBool("isUp", false);
  182. //Debug.Log("Not Moving Up");
  183.  
  184.  
  185. }
  186.  
  187. if (isMovingLeft == true)
  188. {
  189.  
  190. animator.SetBool("isIdleUp", false);
  191. animator.SetBool("isIdleDown", false);
  192. animator.SetBool("isIdleRight", false);
  193. animator.SetBool("isIdleLeft", true);
  194. animator.SetBool("isMoving", false);
  195. animator.SetBool("isUp", false);
  196. // Debug.Log("Not Moving Left");
  197.  
  198.  
  199. }
  200. if (isMovingRight == true)
  201. {
  202. animator.SetBool("isIdleUp", false);
  203. animator.SetBool("isIdleDown", false);
  204. animator.SetBool("isIdleRight", true);
  205. animator.SetBool("isIdleLeft", false);
  206. animator.SetBool("isMoving", false);
  207. animator.SetBool("isUp", false);
  208. // Debug.Log("Not Moving Right");
  209.  
  210.  
  211.  
  212. }
  213. if (isMovingDown == true)
  214. {
  215. animator.SetBool("isIdleUp", false);
  216. animator.SetBool("isIdleDown", true);
  217. animator.SetBool("isIdleRight", false);
  218. animator.SetBool("isIdleLeft", false);
  219. animator.SetBool("isMoving", false);
  220. animator.SetBool("isUp", false);
  221.  
  222. }
  223.  
  224.  
  225.  
  226. }
  227.  
  228.  
  229.  
  230. }
  231.  
  232. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement