Advertisement
shadowx320

Helper.cs

May 2nd, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. namespace SA
  6. {
  7. public class Helper : MonoBehaviour {
  8.  
  9. [Range(0, 1)]
  10. public float vertical;
  11.  
  12. public bool playAnim;
  13. public string[] oh_attacks;
  14. public string[] th_attacks;
  15.  
  16.  
  17. public bool twoHanded;
  18. public bool enableRM;
  19. public bool useItem;
  20. public bool interacting;
  21.  
  22. Animator anim;
  23.  
  24. void Start ()
  25. {
  26. anim = GetComponent<Animator>();
  27. }
  28.  
  29. void Update ()
  30. {
  31.  
  32. enableRM = !anim.GetBool("canMove");
  33. anim.applyRootMotion = enableRM;
  34.  
  35. interacting = anim.GetBool("interacting");
  36.  
  37.  
  38. if (enableRM)
  39. return;
  40.  
  41. if (useItem)
  42. {
  43. anim.Play("use_item");
  44. useItem = false;
  45. }
  46.  
  47. anim.SetBool("two_handed", twoHanded);
  48.  
  49. if(interacting)
  50. {
  51. playAnim = false;
  52. vertical = Mathf.Clamp(vertical, 0, 0.5f);
  53. }
  54.  
  55. if(playAnim)
  56. {
  57. string targetAnim;
  58.  
  59. if(!twoHanded)
  60. {
  61. int r = Random.Range(0, oh_attacks.Length);
  62. targetAnim = oh_attacks[r];
  63. }
  64. else
  65. {
  66. int r = Random.Range(0, th_attacks.Length);
  67. targetAnim = th_attacks[r];
  68. }
  69.  
  70. vertical = 0;
  71.  
  72.  
  73. anim.CrossFade(targetAnim, 0.2f);
  74. //anim.SetBool("canMove",false);
  75. //enableRM = true;
  76. playAnim = false;
  77. }
  78.  
  79. anim.SetFloat("vertical", vertical);
  80. }
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement