Last active
August 29, 2015 14:01
-
-
Save kankikuchi/f2b5c5a865d731510d0f to your computer and use it in GitHub Desktop.
Unityでプレイヤーのアニメーションを管理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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