Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by NashEquilibrium1987 · Mar 11, 2014 at 02:23 PM · iosbuttonsetactive

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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")

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image NashEquilibrium1987 · Mar 12, 2014 at 03:37 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges