我有一个手机游戏,你唯一要做的就是点击跳转,现在我添加了一个暂停菜单,当我点击它时,玩家仍然会跳转,当我点击恢复按钮后,玩家也会跳转,这会让游戏变得很烦人
如何修复?
代码:
public void Pause()
{
Time.timeScale = 0;
panel.SetActive(true);
}
public void Resume()
{
Time.timeScale = 1;
panel.SetActive(false);
}和跳转,如果你问(它在void update中被调用):
void Jump()
{
if (Input.GetMouseButtonDown(0))
{
rb.AddForce(Arrow.transform.right * -ImpulseForce * Time.fixedDeltaTime, ForceMode2D.Impulse);
}
}发布于 2020-07-30 17:03:26
根据您的设置,一种简单的方法是在向刚体添加力之前,使用EventSystem.current.IsPointerOverGameObject()检查当前事件是否在UI GameObject上
void Jump()
{
if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
{
rb.AddForce(Arrow.transform.right * -ImpulseForce * Time.fixedDeltaTime, ForceMode2D.Impulse);
}
}另一种选择是使用光线投射来检查单击的位置(UI或非UI),或者实现IPointerClickHandler / IPointerDownHandler接口之一。
https://stackoverflow.com/questions/63151912
复制相似问题