Advertisement
Guest User

Untitled

a guest
Apr 13th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CharacterAnims : MonoBehaviour
  5. {
  6. public enum anim { None, WalkLeft, WalkRight, RopeLeft, RopeRight, Climb, ClimbStop, StandLeft, StandRight, HangLeft, HangRight, FallLeft, FallRight , ShootLeft, ShootRight }
  7.  
  8. public Transform spriteParent;
  9. public OTAnimatingSprite playerSprite;
  10. //public tk2dAnimatedSprite playerSprite;
  11.  
  12. private anim currentAnim;
  13. private MovementClass character;
  14.  
  15. // Use this for initialization
  16. void Start ()
  17. {
  18. character = GetComponent<MovementClass>();
  19. }
  20.  
  21. void Update()
  22. {
  23. //run left
  24. if(character.isLeft && character.grounded == true && currentAnim != anim.WalkLeft)
  25. {
  26. currentAnim = anim.WalkLeft;
  27. playerSprite.Play("running");
  28. spriteParent.localScale = new Vector3(-1, 1, 1);
  29. }
  30. if(!character.isLeft && character.grounded == true && currentAnim != anim.StandLeft && character.facingDir == MovementClass.facing.Left)
  31. {
  32. currentAnim = anim.StandLeft;
  33. playerSprite.Play("stand"); // stand left
  34. spriteParent.localScale = new Vector3(-1, 1, 1);
  35. }
  36.  
  37. // run right
  38. if(character.isRight && character.grounded && currentAnim != anim.WalkRight)
  39. {
  40. currentAnim = anim.WalkRight;
  41. playerSprite.Play("running");
  42. spriteParent.localScale = new Vector3(1, 1, 1);
  43. }
  44. if(!character.isRight && character.grounded && currentAnim != anim.StandRight && character.facingDir == MovementClass.facing.Right)
  45. {
  46. currentAnim = anim.StandRight;
  47. playerSprite.Play("stand"); // stand right
  48. spriteParent.localScale = new Vector3(1, 1, 1);
  49. }
  50.  
  51. // falling
  52. if(character.grounded == false && currentAnim != anim.FallLeft && character.facingDir == MovementClass.facing.Left)
  53. {
  54. currentAnim = anim.FallLeft;
  55. playerSprite.Play("jump"); // fall left
  56. spriteParent.localScale = new Vector3(-1, 1, 1);
  57. }
  58. if(character.grounded == false && currentAnim != anim.FallRight && character.facingDir == MovementClass.facing.Right)
  59. {
  60. currentAnim = anim.FallRight;
  61. playerSprite.Play("jump"); // fall right
  62. spriteParent.localScale = new Vector3(1, 1, 1);
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement