Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Player Animations Manager, GUENDELI OMAR
- * ce scrîpt va se baser de la State Machine pour modifier les animations selon les etats.
- * j'ai utilisé 2D ToolKit ici, mais marche aussi avec des animations 3D (Animation Component: animation.Play)
- */
- using UnityEngine;
- using System.Collections;
- public class PlayerAnimations : MonoBehaviour {
- private tk2dAnimatedSprite mySprite; // on charge une reference a notre composant animation
- // Use this for initialization
- void Start () {
- mySprite = GetComponentInChildren<tk2dAnimatedSprite>(); // je prefere utiliser un gameobjet vide et tout mettre en child
- }
- // ici on check constament les etat finis de notre personnage pour jouer les animations
- // on verifie aussi si l'animation n'est pas jouée pour eviter de la charger a chaque frame.
- void Update () {
- if (PlayerMovements.playerState == PlayerState.idle && mySprite.clipId != 0)
- {
- mySprite.Play("idle");
- }
- if (PlayerMovements.playerState == PlayerState.running && mySprite.clipId != 1)
- {
- mySprite.Play("run");
- }
- if (PlayerMovements.playerState == PlayerState.jumping && mySprite.clipId != 2)
- {
- mySprite.Play("jump");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement