【问题标题】:Shooting animation in Unity在 Unity 中拍摄动画
【发布时间】:2019-05-21 02:34:16
【问题描述】:

我正在 Unity 中创建拍摄,我已经设置了所有内容,但问题是我希望动画仅在单击时播放,但在我的脚本中,它会在按住按钮时无限播放动画。检查下面的脚本。谢谢。

public GameObject bulletPrefab;
public Transform firePoint;
private Animator anim;
// Start is called before the first frame update
void Start()
{
    anim = GetComponent<Animator>();
}

// Update is called once per frame
void Update()
{
    if (Input.GetKeyDown(KeyCode.Space))
    {
        Instantiate(bulletPrefab, firePoint.position, Quaternion.identity);
        anim.SetBool("isShooting", true);

    }
    if (Input.GetKeyUp(KeyCode.Space))
    {
        anim.SetBool("isShooting", false);
    }

}

【问题讨论】:

  • if (Input.GetKeyUp(KeyCode.Space)) { anim.SetBool("isShooting", false); }
  • 不小心大声笑,但并没有解决问题。

标签: c# unity3d


【解决方案1】:

设置 2 个状态,仅按键开启时间 = 0 结束位置正在射击,结束位置空闲。使用触发参数从空闲到射击。从射击到闲置只是一个时间过渡。 ps拍摄也可以多帧完成。希望对您有所帮助。

【讨论】:

  • 你能解释得更有效率吗?我不明白你的意思,对不起。
  • 我添加了一些图片
  • 脚本呢?
  • 你每次拍摄 Trigger 参数而不是 bool 时调用并让状态自动进入空闲状态
  • 非常感谢,就是这样。
猜你喜欢
  • 2018-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-08
  • 1970-01-01
相关资源
最近更新 更多