所以几天前我刚开始学习统一,而C#还不熟悉 我有一个问题,动画没有播放到最后,只是在中部剪切了,这里是youtube链接,所以您可以检查一下https://www.youtube.com/watch?v=wz5TWh7dTqY
这是我为动画制作的代码
public class PlayerControllerAnimations : MonoBehaviour
{
public Animator anim;
void Start ()
{
anim = GetComponent<Animator>();
}
void Update()
{
//if(Input.GetAxis("Horizontal") != 0)
if (Input.GetAxis("Horizontal") !=0)
{
anim.SetBool("isWalking", true);
}
else if (Input.GetAxis("Vertical") != 0)
{
anim.SetBool("isWalking", true);
}else
{
anim.SetBool("isWalking", false);
}
if (Input.GetKey(KeyCode.LeftShift))
{
anim.SetBool("isSprinting", true);
}else
{
anim.SetBool("isSprinting", false);
}
//if (Input.GetKey(KeyCode.V))
if (Input.GetButtonDown("Roll"))
{
anim.SetBool("isRolling", true);
}
else
{
anim.SetBool("isRolling", false);
}
if (Input.GetButtonDown("Roll") && anim)
{
anim.StopPlayback();
//Stop(GetComponent<Animator>());
}
}
}
这段代码我只是从互联网复制粘贴
private Health Hp;
private Rigidbody Rb;
private Animator Anim;
public float DelayBeforeInvisible = 0.2f;
public float InvisibleDuration = 0.5f;
public float DodgeCoolDown = 1;
private float ActCooldown;
public float PushAmt = 3;
void Start()
{
Hp = GetComponent<Health>();
Rb = GetComponent<Rigidbody>();
Anim = GetComponentInChildren<Animator>();
}
void Update()
{
bool Roll = Input.GetButtonDown("Roll");
if (ActCooldown <= 0)
{
Anim.ResetTrigger("Roll");
if (Roll)
{
Dodge();
}
}
else
{
ActCooldown -= Time.deltaTime;
}
void Dodge()
{
ActCooldown = DodgeCoolDown;
Hp.Invisible(DelayBeforeInvisible, InvisibleDuration);
Rb.AddForce(transform.forward * PushAmt, ForceMode.Force);
Anim.SetTrigger("Roll");
}
}
}
答案 0 :(得分:0)
也许是因为您的滚动动画退出状态设置为isRolling = false
,所以在代码中会显示if (Input.GetButtonDown("Roll"))
else
,这意味着您放开关键点isRolling = false
。如果这是问题,则可以通过在动画过渡中选中“具有退出时间”框来解决。或者,您可以创建一个计时器浮动,以在特定时间将isRolling还原为false。