状态机动画切换出现延时

a839398 2017-12-10 08:35:00
//请教各位大神,我是初学者没什么经验。到了动画切换这里出了两个问题,一个解决了但是不知道什么原理,一个未解决。
//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);
}
}
}
}
...全文
379 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

2,535

社区成员

发帖
与我相关
我的任务
社区描述
Unity3D相关内容讨论专区
游戏unity 技术论坛(原bbs)
社区管理员
  • Unity3D
  • 芝麻粒儿
  • 「已注销」
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

Unity3D社区公告:

  1. 社区致力于解决各种Unity3D相关的“疑难杂症”。
  2. 社区不允许发布与Unity3D或相关技术无关内容。
  3. 社区版主邀请各位一道为打造优秀社区不懈努力。

试试用AI创作助手写篇文章吧