Guest User

Untitled

a guest
May 24th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerControl : MonoBehaviour {
  6.  
  7. Animator animator;
  8. float directionX = 0;
  9. float directionY = 0;
  10. bool walking = false;
  11. float h;
  12. float v;
  13.  
  14. /* Use this for initialization */
  15. void Start () {
  16. animator = GetComponent<Animator>();
  17. }
  18.  
  19. /* Update is called once per frame */
  20. void Update () {
  21. if (animator)
  22. {
  23. h = Input.GetAxisRaw("Horizontal");
  24. v = Input.GetAxisRaw("Vertical");
  25. walking = true;
  26.  
  27. if (h > 0) //「→」↘
  28. {
  29. directionX = 1;
  30. directionY = -0.5F;
  31. }
  32. else if (h < 0) //「←」↖
  33. {
  34. directionX = -1;
  35. directionY = 0.5F;
  36. }
  37. else if (v > 0) //「↑」↗
  38. {
  39. directionX = 1;
  40. directionY = 0.5F;
  41. }
  42. else if (v < 0) //「↓」↙
  43. {
  44. directionX = -1;
  45. directionY = -0.5F;
  46. }
  47. else
  48. {
  49. walking = false;
  50. }
  51. }
  52. else
  53. {
  54. walking = false;
  55. }
  56.  
  57. if (walking == true)
  58. {
  59. transform.Translate(new Vector3(directionX, directionY, 0));
  60. }
  61. animator.SetFloat("Direction_X", directionX);
  62. animator.SetFloat("Direction_Y", directionY);
  63. animator.SetBool("isWalk", walking);
  64.  
  65. walking = false;
  66. }
  67. }
Add Comment
Please, Sign In to add comment