Advertisement
Guest User

PlayerAnimations

a guest
Jan 30th, 2013
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. /*
  2.  * Player Animations Manager, GUENDELI OMAR
  3.  * ce scrîpt va se baser de la State Machine pour modifier les animations selon les etats.
  4.  * j'ai utilisé 2D ToolKit ici, mais marche aussi avec des animations 3D (Animation Component: animation.Play)
  5. */
  6. using UnityEngine;
  7. using System.Collections;
  8.  
  9. public class PlayerAnimations : MonoBehaviour {
  10.  
  11.     private tk2dAnimatedSprite mySprite; // on charge une reference a notre composant animation
  12.  
  13.     // Use this for initialization
  14.     void Start () {
  15.         mySprite = GetComponentInChildren<tk2dAnimatedSprite>(); // je prefere utiliser un gameobjet vide et tout mettre en child
  16.     }
  17.    
  18.     //  ici on check constament les etat finis de notre personnage pour jouer les animations
  19.     //  on verifie aussi si l'animation n'est pas jouée pour eviter de la charger a chaque frame.
  20.     void Update () {
  21.         if (PlayerMovements.playerState == PlayerState.idle && mySprite.clipId != 0)
  22.         {
  23.             mySprite.Play("idle");
  24.         }
  25.         if (PlayerMovements.playerState == PlayerState.running && mySprite.clipId != 1)
  26.         {
  27.             mySprite.Play("run");
  28.         }
  29.         if (PlayerMovements.playerState == PlayerState.jumping && mySprite.clipId != 2)
  30.         {
  31.             mySprite.Play("jump");
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement