How do you use Rect.contains on iphone or android to replace gui?
I’m a huge noob when it comes to it and I can’t even figure out how to show the rect visually so I know where it is.
Any examples will help
Thanks
I’m completely stupid about iPhone or Android, but already used Rect.Contains in a similar application. Supposing GUI works in mobile devices, I would use GUI.Box just to see the sensible areas, then rename or delete the OnGUI function when everything was ok - something like this:
// define the rects
var r1 = Rect(10,10,200,80); // left, top, width, height
var r2 = Rect(10,100,100,100);
var r3 = Rect(120,100,100,100);
function OnGUI(){ // use this to see the areas covered
GUI.Box(r1, "area1"); // you can modify the rects until
GUI.Box(r2, "area2"); // they cover the desired areas, then
GUI.Box(r3, "area3"); // rename the function to deactivate it
}
// Check the areas with "rN.Contains" when the screen is touched - again, I'm
// a total void about touches; please fix any stupid thing I may have done
// in this touch stuff
function Update(){
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began){
var pos = Input.GetTouch(0).position;
if (r1.Contains(pos)){
// area 1 touched
}
if (r2.Contains(pos)){
// area 2 touched
}
if (r3.Contains(pos)){
// area 3 touched
}
}
}