Hi.
due to unity’s GUI system not working great with multi-touch on android devices I had to make a work-around where I create 3 rect that I draw a texture in and check if the player is touching within that rect.
but for some reason. it only works with one of the buttons
The variables:
public Texture redButtonTexture;
public Texture greenButtonTexture;
public Texture blueButtonTexture;
public Rect redButtonRect;
public Rect greenButtonRect;
public Rect blueButtonRect;
Setting the value of the rects in Start()
redButtonRect = new Rect(0, colorButtonHeight * 2, Screen.width / 5, colorButtonHeight);
greenButtonRect = new Rect(0, colorButtonHeight * 3, Screen.width / 5, colorButtonHeight);
blueButtonRect = new Rect(0, colorButtonHeight * 4, Screen.width / 5, colorButtonHeight);
Drawing the texture in OnGUI()
GUI.DrawTexture(redButtonRect, redButtonTexture);
GUI.DrawTexture(greenButtonRect, greenButtonTexture);
GUI.DrawTexture(blueButtonRect, blueButtonTexture);
and checking for touch in the Update()
foreach (Touch touch in Input.touches)
{
if(redButtonRect.Contains(touch.position))
{
Debug.Log ("red");
}
if(greenButtonRect.Contains(touch.position))
{
Debug.Log ("green");
}
if(blueButtonRect.Contains(touch.position))
{
Debug.Log ("blue");
}
}
For some weird reason, that I can’t explain. Then it’s only the Red button that works and I can’t get the green and blue buttons to work. no matter what I do…
It’s possible for me to place GUITexture onto the screen and use them but then I’d have to position them correctly every time the game starts so that the size and position fits the device…
does anyone have a solution to this problem? or can you see what I did wrong in my code?
Thanks
-Frank