Skip to content

Instantly share code, notes, and snippets.

@kankikuchi
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kankikuchi/f2b5c5a865d731510d0f to your computer and use it in GitHub Desktop.
Save kankikuchi/f2b5c5a865d731510d0f to your computer and use it in GitHub Desktop.
Unityでプレイヤーのアニメーションを管理
using UnityEngine;
using System.Collections;
public class PlayerAnimScript : MonoBehaviour
{
//Animationの種類
public enum AnimeName
{
idle,
run,
walk
}
private string[] AnimeNameArray = {
"idle", "run", "walk",
};
public int AnimeNoNow, AnimeNoWas;
public float AnimeSpeedNow, AnimeSpeedWas;
//==========================================
//設定
//==========================================
void Start ()
{
AnimeNoNow = (int)AnimeName.idle;
AnimeNoWas = -1;
AnimeSpeedNow = 1.0f;
AnimeSpeedWas = 1.0f;
}
//==========================================
//アニメ切り替え
//==========================================
public void AnimeSet (int AnimeNo, float AnimeSpeed)
{
AnimeNoNow = AnimeNo;
AnimeSpeedNow = AnimeSpeed;
}
void Update ()
{
if (AnimeNoNow != AnimeNoWas || AnimeSpeedNow != AnimeSpeedWas) {
foreach (AnimationState anim in animation) {
if (anim.name.IndexOf (AnimeNameArray [AnimeNoNow]) >= 0) {
animation.animation [anim.name].speed = AnimeSpeedNow;
animation.CrossFade (anim.name);
break;
}
}
AnimeNoWas = AnimeNoNow;
AnimeSpeedWas = AnimeSpeedNow;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment