SpineboyPole.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using UnityEngine;
  2. using System.Collections;
  3. using Spine.Unity;
  4. using Spine.Unity.Modules;
  5. public class SpineboyPole : MonoBehaviour {
  6. public SkeletonAnimation skeletonAnimation;
  7. public SkeletonRenderSeparator separator;
  8. [Space]
  9. [SpineAnimation]
  10. public string run;
  11. [SpineAnimation]
  12. public string pole;
  13. public float startX;
  14. public float endX;
  15. const float Speed = 18f;
  16. const float RunTimeScale = 1.5f;
  17. IEnumerator Start () {
  18. var state = skeletonAnimation.state;
  19. while (true) {
  20. // Run phase
  21. SetXPosition(startX);
  22. separator.enabled = false; // Disable Separator during run.
  23. state.SetAnimation(0, run, true);
  24. state.TimeScale = RunTimeScale;
  25. while (transform.localPosition.x < endX) {
  26. transform.Translate(Vector3.right * Speed * Time.deltaTime);
  27. yield return null;
  28. }
  29. // Hit phase
  30. SetXPosition(endX);
  31. separator.enabled = true; // Enable Separator when hit
  32. var poleTrack = state.SetAnimation(0, pole, false);
  33. yield return new WaitForSpineAnimationComplete(poleTrack);
  34. yield return new WaitForSeconds(1f);
  35. }
  36. }
  37. void SetXPosition (float x) {
  38. var tp = transform.localPosition;
  39. tp.x = x;
  40. transform.localPosition = tp;
  41. }
  42. }