Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. using Assets.HeroEditor.Common.CharacterScripts;
  2. using UnityEngine;
  3.  
  4. public class PlayerMovement : MonoBehaviour {
  5.  
  6. public float XAxis;
  7. public float YAxis;
  8. public CharacterController2D controller;
  9. public Animator anim;
  10. public float runSpeed = 40f;
  11.  
  12. public Joystick joystick;
  13.  
  14. float horizontalMove = 0f;
  15. bool Jump = false;
  16. bool Crouch = false;
  17. public Character Character;
  18.  
  19.  
  20.  
  21. private void OnTriggerEnter2D(Collider2D other){
  22. if(other.gameObject.CompareTag("Coins"))
  23. {
  24. Destroy(other.gameObject);
  25. }
  26.  
  27. if (other.tag == "Fall")
  28. {
  29. Vector2 newPosition = new Vector2(XAxis,YAxis);
  30. transform.position = newPosition;
  31. }
  32.  
  33.  
  34. }
  35.  
  36. // Update is called once per frame
  37. void Update () {
  38.  
  39.  
  40. //horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
  41. horizontalMove = joystick.Horizontal * runSpeed;
  42. controller.Move(horizontalMove * Time.fixedDeltaTime, Crouch, Jump);
  43. Jump = false;
  44.  
  45. //This Is for Idle Animation
  46. if (Input.GetAxisRaw("Horizontal") == 1)
  47. {
  48. Character.Animator.SetBool("Idle", true);
  49. }
  50. else if (Input.GetAxisRaw("Horizontal") == -1)
  51. {
  52. Character.Animator.SetBool("Idle", true);
  53. }
  54. else
  55. {
  56. Character.Animator.SetBool("Idle", false);
  57. }
  58.  
  59. //This Is for jumping Animation
  60. if (Input.GetButtonDown("Jump"))
  61. {
  62. Jump = true;
  63. Character.Animator.SetBool("Jump", true);
  64. }else
  65. {
  66. Jump = false;
  67. Character.Animator.SetBool("Jump", false);
  68. }
  69. //This Is for Crouching Animation
  70. if (Input.GetButtonDown("Crouch"))
  71. {
  72. Crouch = true;
  73. Character.Animator.SetBool("Crouch", true);
  74.  
  75. } else if (Input.GetButtonUp("Crouch"))
  76. {
  77. Crouch = false;
  78. Character.Animator.SetBool("Crouch", false);
  79. }
  80. //This Is for Walking Animation
  81. if (joystick.Horizontal >= 0.4)
  82. {
  83. Character.Animator.SetBool("Walk", true);
  84. }else if (joystick.Horizontal <= -0.4)
  85. {
  86. Character.Animator.SetBool("Walk", true);
  87. }else
  88. {
  89. Character.Animator.SetBool("Walk", false);
  90. }
  91. //This Is for Running Animation
  92. if (joystick.Horizontal >= 0.5)
  93. {
  94. Character.Animator.SetBool("Run", true);
  95. }else if (joystick.Horizontal <= -0.5)
  96. {
  97. Character.Animator.SetBool("Run", true);
  98. }else
  99. {
  100. Character.Animator.SetBool("Run", false);
  101. }
  102.  
  103.  
  104.  
  105. }
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement