- Home /
GUI.Button works on desktop player but not iOS
Hello,
I have a GUI Button that controls taking a screenshot, and that works fine. On the desktop player and on iOS.
I also have a GUI Button that controls if an object is visible. On the desktop player the button works fine. However when I come to test it on an iOS device the button hiding an object doesn't work
void OnGUI() {
if (shouldDraw) {
if (GUI.Button(new Rect(Screen.width/25f, Screen.height-120f, Screen.width/3f,25f), "Photo")) {
ap.targetTexture = photo;
ap.Photo();
}
if (GUI.Button(new Rect(Screen.width/25f, Screen.height-150f, Screen.width/3f,25f), "On/Off Object 1")) {
GO_1.SetActive(!GO_1.activeSelf);
}
}
}
Does anybody have any ideas on what the issue is? Or better yet a fix?
Answer by DMTSource · Mar 11, 2014 at 02:35 PM
Hi, I would take a look at the way Rect is being used and how it will change for different resolutions(PC vs the IOS).
From the documentation: Rect(float left, float top, float width, float height);
I would suggest using relative sizes for both the width, and height. The value 25f is going to be too small probably on mobile resolution. Try something like Screen.height*0.1f instead of 25f.
The position values should also use relative positioning and divide or multiply by a value under 1 instead of adding or subtracting interpreted pixel values( screen density and resoltuon on mobile devices will make relative positioning and size very important)
For example maybe something like this will have better results on mobile:
GUI.Button(new Rect(Screen.width*0.01f, Screen.height*0.8f, Screen.width*0.3f, Screen.height*0.1f), "Photo")
For anyone else who has this problem, I eventually settled on:
if(GUI.Button(new Rect(10, Screen.height-100, 120, 60), "Obj1 On/Off"))
{
if(GO_1.active == true)
{
GO_1.active = false;
}
else
{
GO_1.active = true;
}
}
Your answer
Follow this Question
Related Questions
Screenshot certain layers so it doesn't show GUI Button on the image?? 0 Answers
Unity iOS CompileC error while building through Xcode 1 Answer
one button to hide and unihed gameobjects 0 Answers
physics.OverlapSphere colliders 1 Answer
Is SetActive doesn't working or the button dont work? [Solved] 1 Answer