Making UI block rays with touch inputs
Hello everyone!
I am trying to make a mobile game and am using touch input for the first time. I have tried making it so the raycasts to tap on objects are checked for whether the pointer is over a game object in the EventSystem as you see it in so many tutorials online and here as explained by @fafase and I tried a few versions. Down here is the first version that worked but now everything is being detected as UI and no rays sent out anymore at all? I would very much appreciate some help if someone has solved a similar problem before!
Thank you!
private int fingerID = -1;
private void Awake()
{
#if !UNITY_EDITOR
fingerID = 0;
#endif
}
private void Update()
{
if (Input.touchCount == 1 && theTouch.phase == TouchPhase.Ended)
{
//checking whether the UI was touched
if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId) == false)
{
Debug.Log("UI touched");
return;
}
//All the raycasting stuff
}
}
Your answer
Follow this Question
Related Questions
Scripting Errors 1 Answer
How to pass event info to events? 1 Answer
UI doesn't work in Editor sometime and never on tablet 0 Answers
OnPointerEnter blocked by something 2 Answers
How do I press an UI button with Gamepad controls? 0 Answers