Why is my Touches array empty?

I am using CnInputControls.
When I click a button it seems to pass multiple events to the Update method.

I tried using the following code


But I then get IndexOutOfBounds in the GetTouch because the touches array is empty.

If I leave out the GetTouch part then the if statement is always true.

What am I missing?

I don’t have experience with CnInputManager, but I used regular Unity touch input for an app a few years back. It looks the same, but please bear with me if it works entirely different!

What seems a little odd to me is how you combine “get button down” and GetTouch(0). I would guess it should be something like this (with regular Unity input stuff)

 if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) 

Usually this type of structure is made to make sure we don’t start looking for Touch 0 before we’re actually sure there is one. The && operator is lazy, meaning that if the left side is false, it won’t evaluate the right side, saving us the null pointer exception that it would cause.

Of course, the whole ButtonDown && GetTouch(0) might just be some CnInput stuff that I’m not familiar with.