- Home /
why doesn't my touch-position conditional statements work for mobile app?
So i created a texture to represent my start button and added 4 empty game objects named LB, RB, TB, and BB (leftborder, rightborder, topborder, bottomborder) as children of the start button texture and aligned them respectively (ex: leftborder aligned with the left border of my texture). I then set the conditional statement down below however it is not executing. could this be because Input.GetTouch (0).position.x returns coordinates values between 0-1 while my border transforms have -position values? *I've already checked that the co-routine works
GameObject startbutton01 = new GameObject ();
GameObject startbutton02 = new GameObject ();
public GameObject startbutton1;
public GameObject startbutton2;
public Transform startbuttonspawn;
private bool Busy = false;
public Transform LB;
public Transform RB;
public Transform TB;
public Transform BB;
void Start () {
}
void Update () {
Touch touch = Input.GetTouch (0);
if (Input.touchCount > 0 && touch.phase == TouchPhase.Began && Busy == false && touch.position.x >= LB.position.x && touch.position.x <= RB.position.x && touch.position.y <= TB.position.y && touch.position.y >= BB.position.y) {
StartCoroutine (buttonAnim());
}
}
IEnumerator buttonAnim(){
Busy = true;
Destroy (startbutton01);
Destroy (startbutton02);
startbutton01 = Instantiate (startbutton2, startbuttonspawn.position, startbuttonspawn.rotation) as GameObject;
yield return new WaitForSeconds (1);
startbutton02 = Instantiate (startbutton1, startbuttonspawn.position, startbuttonspawn.rotation) as GameObject;
Destroy (startbutton01);
Busy = false;
}
}
so ive learned a couple things since last post, that (0,0) in the screen space coordinate system is bottom-left while the information returned by Input.GetTouch (0).position.x may have (0,0) at topleft, i tried to look for this in the documentation but failed so i'm not sure and need help **even though i'm deriving the coordinates from empty gameobjects attached to the texture, does this still give me a different coordinate system value when being run on a phone?
all these different coordinates systems is giving me a real headache (especially since i cant directly test my app on my phone and have to do it manually). so i need conformation on the following things: *to position things in phone i must use 0-1 coordinate system with (0,0) originating bottom-left? *Unity screen space uses pixel coordinate system with (0,0) originating top-left? *to potentially position something correctly on my phone i would have to, first, convert the values so both coordinate system's (0,0) are bottom-left, second, i would have to convert the number of pixels in the pixel coordinate system to 0-1 to match the phone positioning system of phone.?