Guest User

Untitled

a guest
Jun 10th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using Spine.Unity;
  4.  
  5. public class SpineboyMover : MonoBehaviour
  6. {
  7.  
  8. // Use this for initialization
  9. public float speed = 5;
  10. public Transform graphics;
  11.  
  12. public SkeletonAnimation skeletonAnimation;
  13. float x;
  14.  
  15. string currentAnimation = "";
  16.  
  17. void Update()
  18. {
  19. x = Input.GetAxis("Horizontal") * speed;
  20.  
  21. if (x > 0) {
  22. graphics.localRotation = Quaternion.Euler(0, 0, 0);
  23. SetAnimation("run", true);
  24. }
  25. else if (x < 0) {
  26. graphics.localRotation = Quaternion.Euler(0, 180, 0);
  27. SetAnimation("run", true);
  28. }
  29. else{
  30. SetAnimation("idle", true);
  31. }
  32.  
  33. }
  34.  
  35. void SetAnimation(string name , bool loop){
  36. if (name == currentAnimation)
  37. return;
  38.  
  39. skeletonAnimation.state.SetAnimation(0, name, loop);
  40. currentAnimation = name;
  41. }
  42.  
  43. void FixedUpdate() {
  44. GetComponent<Rigidbody2D>().velocity = new Vector2(x, GetComponent<Rigidbody2D>().velocity.y);
  45.  
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment