【发布时间】:2020-06-01 22:44:44
【问题描述】:
我正在开发一款小型节拍游戏作为暑期项目。当按下一个键时,我试图改变精灵动画。
这是我的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
Animator anim;
void Start()
{
anim = gameObject.GetComponent<Animator>();
}
void Update()
{
if (this.anim.GetCurrentAnimatorStateInfo(0).IsName("Jotaro Idle"))
{
if (Input.GetKey(KeyCode.D))
anim.SetTrigger("WalkRightfromIdle");
else if (Input.GetKey(KeyCode.A))
anim.SetTrigger("WalkLeftFromIdle");
}
}
}
这是我的动画窗口的截图(每个转换都由一个触发器控制):https://imgur.com/a/f93GrAn
任何帮助将不胜感激。
【问题讨论】:
-
这里你应该使用 Bools 而不是触发器,例如
isWalkingLeft和isWalkingRight并执行类似if isWalkingLeft=> 进入向左行走状态,if isWalkingRight=> 进入向右行走状态,如果两者都没有 => 进入空闲状态
标签: c# unity3d sprite animator