- Home /
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
if(CnInputManager.GetButtonDown("Fire3")&&CnInputManager.GetTouch(0).phase==TouchPhase.Began){
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?
Answer by NerdClown · Sep 01, 2016 at 07:29 AM
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.
The GetButtonDown also exists in Input and is meant to give me the button that was clicked. GetButton works just as well.
Nevertheless, touchCount is always 0. I never get any touches from it.
Yes, that is true, but I guess what is bothering me is the combination of GetTouch and GetButton/GetButtonDown.
The reason I'm confused is probably that in my perception, the GetTouch is for touch devices like phones or tablets while the GetButtonDown I only ever used for things that has actual buttons ... like mouse/keyboard and such.
What type of device is your project gonna run on?
$$anonymous$$aybe that is my problem. I am new to all this.
It is going to run on Android but I am testing it inside Unity because I can't get UnityRemote to work. $$anonymous$$aybe that is my problem.
Your answer
Follow this Question
Related Questions
InputManager crashes unity when downloaded from the Asset Server. 1 Answer
How to add custom input to InputManager? 2 Answers
guitexture to act as a button on the keyboard or mouse 0 Answers
Input Manager: Gamepad axis only won't work (however buttons does) 0 Answers
Input Snap option not returning 0? 0 Answers