【发布时间】:2020-08-24 21:59:29
【问题描述】:
所以我是几天前开始接触统一的,并且是 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");
}
}
}
【问题讨论】:
-
您的 Unity 动画树可能有问题,请检查转换是否按预期工作。