【发布时间】:2021-02-18 19:02:06
【问题描述】:
我不擅长 3D 动画,所以我有一个小问题。我正在用蝙蝠制作摆动动画。每个动画都可以正常工作,但是这里的问题是,当从空闲动画转到摆动动画时,它会卡住,我必须单击几次才能返回空闲状态。 here is the animation
和
Here is where the thing gets stuck
在这里你可以检查这两个 trainsition 的检查器:
from idle to swing from swing to idle
我正在尝试解决这个问题一段时间,但仍然不明白为什么会这样。 在这里您可以查看此代码。该脚本专门用于近战武器,但我认为它也适用于其他物品。代码中的所有内容都有效,除了这个动画部分。
using UnityEngine;
public class melee : MonoBehaviour
{
public float dmg;
public float range;
private Animator anim;
private bool attacking = false;
public Camera cam;
void Start(){
anim = gameObject.GetComponent<Animator>();
}
void FixedUpdate(){
AnimatorStateInfo info = anim.GetCurrentAnimatorStateInfo(0);
if(Input.GetButtonDown("Fire1")){
Attack();
}else if(Input.GetButtonUp("Fire1")){
anim.SetBool("attacking", false);
}
}
void Attack(){
RaycastHit hit;
if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, range)){
Debug.Log(hit.transform.name);
enemyHealth enemy = hit.transform.GetComponent<enemyHealth>();
if(enemy != null){
enemy.TakeDmg(dmg);
}
}
anim.SetBool("attacking", true);
}
}
【问题讨论】:
标签: c# unity3d game-engine