Unity通过代码控制动画范例脚本,从⽽实现对动画的全局控制
using UnityEngine;
using System.Collections;
public class AnimationManager : MonoBehaviour {
/// <summary>
/// 创建动画动画控制委托,后⾯创建播放动画⽅法,然后就调⽤就可以直接⽤委托的对象来调⽤
/// 例:animationHandler = xxx,
云开见日
/// </summary>
public delegate void AnimationHandler();
/// <summary>
/// 创建动画对象
/ct什么意思
// </summary>
Animation animation;
/// <summary>
海淀翻译公司/// 创建动画控制器单例
/// </summary>
public static AnimationManager instance;
/// <summary>
/// 创建各个动画,外⾯赋值
/// </summary>
public AnimationClip Dead;
public AnimationClip JumpDown;
public AnimationClip JumpLoop;
public AnimationClip JumpUp;
public AnimationClip Roll;
public AnimationClip Run;
public AnimationClip TurnLeft;
public AnimationClip TurnRight;
/// <summary>
/// 实例化委托
/// </summary>
public AnimationHandler animationHandler;
// U this for initialization
void Start () {
//初始化单例
instance = this;
//默认播放奔跑动画
animationHandler = PlayRun;
//拿到动画组件,挂载在本体上的
bacanimation = GetComponent<Animation>();
}
/// <summary>
/// 播放各个动画
/// </summary>
乐宁教育
#region
public void PlayDead()
{
gwianimation.Play(Dead.name);
}
public void PlayJumpDown()
{
animation.Play(JumpDown.name);
}
public void PlayJumpLoop()
{
animation.Play(JumpLoop.name);
}
public void PlayJumpUp()
{
animation.Play(JumpUp.name);
if (animation[JumpUp.name].normalizedTime > 0.95f)
{
animationHandler = PlayRun;
}
}
public void PlayRoll()
{
animation.Play(Roll.name);
if (animation[Roll.name].normalizedTime > 0.95f)
{
animationHandler = PlayRun;
PlayerController.instance.isRoll = fal;
}
el
{
plasticPlayerController.instance.isRoll = true;
}
}
public void PlayDoubleJump()
{
animation.Play(Roll.name);
if (animation[Roll.name].normalizedTime > 0.95f)
{
animationHandler = PlayJumpLoop;
}
}
public void PlayRun()
{
animation.Play(Run.name);
}
public void PlayTurnLeft()
bedding
{
animation.Play(TurnLeft.name);
if(animation[TurnLeft.name].normalizedTime > 0.95f)
{
animationHandler = PlayRun;
}
}
public void PlayTurnRight()
{
animation.Play(TurnRight.name);
if (animation[TurnRight.name].normalizedTime > 0.95f)
{
animationHandler = PlayRun;
}
}
#endregion
// Update is called once per frame
void Update () {
if(animationHandler !=null)
{
//在update⾥⾯实时判断委托播放动画培训班招生简章
animationHandler();
}
}
}
G
M
T
Detect languageAfrikaansAlbanianAmharicArabicArmenianAzerbaijaniBasqueBelarusianBengaliBosnianBulgarianCatalanCebuanoChichewaChine (Simplified)Chine
(Traditional)CorsicanCroatianCzechDanishDutchEnglishEsperantoEstonianFilipinoFinnishFrenchFrisianGalicianGeorgianGermanGreekGujaratiHaitian
CreoleHausaHawaiianHebrewHindiHmongHungarianIcelandicIgboIndonesianIrishItalianJapaneJavaneKannadaKazakhKhmerKoreanKurdishKyrgyzLaoLatinLatvianLithuanianLuxembourgishMacedon (Burme)NepaliNorwegianPashtoPersianPolishPortuguePunjabiRomanianRussianSamoanScots
adwareGaelicSerbianSesothoShonaSindhiSinhalaSlovakSlovenianSomaliSpanishSundaneSwahiliSwedishTajikTamilTeluguThaiTurkishUkrainianUrduUzbekVietnameWelshXhosaYiddishYorubaZulu
Text-to-speech function is limited to 200 characters
: : :Clo