- Home /
TouchPhase won't return anything but Began
I'm using Unity 4, working on an Android game. When I put the following code at the beginning of my Update function:
myGUI.text = Input.touches[0].phase + "";
it works perfectly, prints Moved when I move my finger, prints Stationary when I don't, etc. myGUI is a GUIText object.
But when I put that same snippet of code after this code:
if (Input.touches[0].phase == TouchPhase.Began) {
if (Input.touches[0].position.y < scrnW/2) {
rightTouchNum = 1; }
else if (Input.touches[0].position.y > scrnW/2) {
leftTouchNum = 1; }
}
else if (Input.touches[1].phase == TouchPhase.Began) {
if (Input.touches[1].position.y < scrnW/2) {
rightTouchNum = 2; }
else if (Input.touches[1].position.y > scrnW/2) {
leftTouchNum = 2; }
}
It won't return anything but Began. Why is this?? How can I possibly be altering the results of touchphase with these if statements? rightTouchNum, leftTouchNum and scrnW are just integers.
I've attached my code for good measure. Thank you!
[1]: /storage/temp/7988-touchcube.js.zip
Answer by ALAN! · Feb 18, 2013 at 06:35 AM
Figured it out! Turns out i'm a big old dummy. Here's the correct code
if(Input.touchCount > 0)
{
//When finger is touched down, determines if left or right:
if (Input.touches[0].phase == TouchPhase.Began) {
if (Input.touches[0].position.y < scrnW/2) {
rightTouchNum = 1; }
else if (Input.touches[0].position.y > scrnW/2) {
leftTouchNum = 1; }
}
if (Input.touchCount >1) {
if (Input.touches[1].phase == TouchPhase.Began) {
if (Input.touches[1].position.y < scrnW/2) {
rightTouchNum = 2; }
else if (Input.touches[1].position.y > scrnW/2) {
leftTouchNum = 2; }
}
}
}
Answer by Paulo-Henrique025 · Feb 17, 2013 at 10:08 PM
I can't see anything wrong with your code, just for testing try this:
switch(Input.touches[0].phase)
{
case TouchPhase.Began:
break;
case TouchPhase.Moved:
break;
case TouchPhase.Ended:
break;
}
Still having the same problem. If I put that code you gave me before that chunk of code I posted, all three cases are activated at the appropriate time. But I post it after, only the first case is ever activated
Send an email to support, your issue seems rather uncommon.
Ok, thanks for the advice! I emailed them my problem. If anyone else has any ideas or would like to try my code and see how it works for them, that would be pretty rad guys
Your answer
![](https://koobas.hobune.stream/wayback/20220613092855im_/https://answers.unity.com/themes/thub/images/avi.jpg)