我正在制作简单的巫婆游戏,玩家触摸屏幕上的任何地方来做一些事情。这是一种反射游戏。同时,我在屏幕上有允许暂停游戏的按钮。问题是,当我点击一个按钮时,游戏同时检测到一个屏幕触摸,我想避免这种情况。我使用的布尔值,我改变了按钮,但它仍然不能正常工作-游戏暂停后,只有一小部分秒后,屏幕触摸被检测到。
我的暂停游戏代码:
GameControlerScript:
public static bool isPaused;
public void PauseGame()
{
isPaused = true; // this is static
Time.timeScale = 0.0f;
//more code here
}
我在附加在不同物体上的脚本中的触摸检测:
void Update()
{
if (((Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) || (Input.GetKeyDown(KeyCode.Space))) && !GameControllerScript.isPaused)
{
// code here starts to be executed and then pasues because of timescale
}
}
那么,有没有办法在isPaused布尔值检测到scrren触摸之前对其进行更改?
发布于 2016-04-21 05:10:32
检查您的触摸是否在UI元素上,如果它没有调用您为正常输入调用的任何方法
public void Update()
{
foreach (Touch touch in Input.touches)
{
if (EventSystem.current.IsPointerOverGameObject(touch.fingerId))
{
// you touched at least one UI element
return;
}
}
// you didnt touched any UI element
// Do Something
}
https://stackoverflow.com/questions/36754676
复制相似问题