【发布时间】: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); }
-
不小心大声笑,但并没有解决问题。