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 AngryCSharpNerd · Oct 19, 2013 at 04:52 PM · guibox

Custom GUI.Box function dilemma

I wanted to created a special GUI.Box() function, called _BOX().

What it would do is that instead of having a box appear, it would have it's own fancy animation that would resize itself automatically, basically how the pop up windows work in Super Mario World.

The problem is that the function needs to repeatedly resize itself, but now that the function would be called in OnGUI(), an UPDATE function, it would cause super-lag.

 function _BOX(rect:Rect,s:String){
     GUI.Box(rect,s);
         
         //see? to put a 'for' loop right here would cause massive lag,
         //due to the fact that this function will be called in an OnGUI, but not doing so only results in the GUI box to just resize by one pixel.
        //i do not want to have two variables outside of this function either, it's not too efficient as i will call this _BOX function many times
     rect.width += 1;
     rect.height += 1;
 }
 
 function OnGUI(){
     _BOX(new RectC(200,100),"Hello World!"); //ignore my RectC function
 }
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

Answer by YoungDeveloper · Oct 19, 2013 at 05:05 PM

Loops which are not very long (talking about tens of thousands of lines) is not that bad in update or ongui. If you think about what basically is for or other loop, it is an instructed way do to things many times. So here's an example in code, these two examples are almost the same, "almost" because for for loop it will need extra i variable and two small operations: i++ and check if i>5, which are checked only once before each instance of loop.

 //This isn't that bad, right ?
 OnGUI(){
     Debug.Log("print message operation");
     Debug.Log("print message operation");
     Debug.Log("print message operation");
     Debug.Log("print message operation");
 }

 //So why should be bad ? But this will use a tiny bit more resources, as i mentioned
 OnGUI(){
     for(int i = 0;i < 5; i++){
         Debug.Log("print message operation");
     }
 }
Comment
Add comment · 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

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

15 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

Related Questions

GUI box problem? 0 Answers

my GUI.box is transparent 1 Answer

Where is my HP Bar? 3 Answers

Applying a script to multiple gui boxes 0 Answers

Strange behaviour GUI.Box 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