状态机动画切换出现延时
//请教各位大神,我是初学者没什么经验。到了动画切换这里出了两个问题,一个解决了但是不知道什么原理,一个未解决。
//1、状态机的Bool类型和Trigger类型各有什么优劣?
//为什么我在Layout用Bool值动画切换用不了,还显示没找到动画。用Trigger就可以切换。(只是两个动画之间切换)
//2、为什么我在Layout第二层的动画切换会延时?
public class PlayerAnimation : MonoBehaviour {
public static PlayerAnimation _instance;
private Animator anim;
void Awake() {
_instance = this;
}
void Start() {
anim = TranscriptManager._instance.player.GetComponent<Animator>();
}
//调用这个函数实现动画切换,这个函数挂在四个按钮上,由参数posType区分
public void AttackButtonOnClick(bool isOnPress,PosType posType) {
if (posType == PosType.Basic)
{
if (isOnPress)
{
anim.SetTrigger("AttackStates");//执行这句代码动作播放延时
}
}
else {
//anim.SetBool("skill0" + (int)posType,true);//这句代码执行,状态机显示没动画
//在这里本来状态机使用Bool值的,但是动画老是丢失,换回了用SetTrigger
anim.SetTrigger("skill0"+(int)posType);//这句代码才执行正常
}
}
}
================================================================================
public class AttackButton : MonoBehaviour {
public PosType posType;
private PlayerAnimation playerAnimation;
private UISprite MaskSprite;
private UIButton btn;
public float coldTime = 10;
public float Timer = 0;
void Start() {
playerAnimation = TranscriptManager._instance.player.GetComponent<PlayerAnimation>();
if (transform.Find("Mask")) {
MaskSprite = transform.Find("Mask").GetComponent<UISprite>();
}
btn=this.GetComponent<UIButton>();
}
void OnPress(bool isOnPress) {
playerAnimation.AttackButtonOnClick(isOnPress,posType);
if (isOnPress&&posType!=PosType.Basic) {
Timer = coldTime;
this.GetComponent<Collider>().enabled = false;
btn.SetState(UIButtonColor.State.Normal,true);
}
}
//---------------------------下面Update()的是冷却效果的
void Update() {
if (posType == PosType.Basic)
{
return;
}
else {
if (Timer > 0)
{
Timer -= Time.deltaTime;
MaskSprite.fillAmount = Timer / coldTime;
}
else
{
Timer = 0;
MaskSprite.fillAmount = 0;
this.GetComponent<Collider>().enabled = true;
btn.SetState(UIButtonColor.State.Normal, true);
}
}
}
}