• 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 StigC · Mar 27, 2014 at 01:38 AM · ontriggerenterguitextureguilayoutgui.boxtext box

Designing a GUI.Box help/guides?

Hi there!

I would love some help on setting up a GUI.Box's design. **I'm very new to GUI, but I've gathered the following code so far:*


 #pragma strict
 
 var showPhoto : boolean;
 var windowRect : Rect;
 var AddPhoto : Texture2D;
  
 function OnGUI(){
    if(showPhoto){
       GUI.Box( windowRect, AddPhoto);
       windowRect = Rect(Screen.width/2-300, Screen.height/2-300, 1000, 600);
       
    }
 }
  
  
 function OnTriggerStay(){
    if(Input.GetKeyDown( KeyCode.L )){
    //showPhoto = true;
    showPhoto = !showPhoto;
 }
  
 }
  
 function OnTriggerExit(){
  
    showPhoto = false;
  
 }


What I'd like to do is:

  • Assign a certain spot to the left for my AddPhoto var, and a text box to the right.

  • Make the Box black and transparent.

  • Maybe have an X in corner.

It looks like this at the moment: alt text

And I need it look somewhat like this:

alt text

I've never really played around with GUI before, so any guide or help would be appreciated! Thanks.

Comment
Add comment · Show 1
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 getyour411 · Mar 27, 2014 at 01:52 AM 0
Share

This question and its cousin (how do I...GUI Design) has been asked a thousand times with a thousand examples, tuts, docs out there.

1 Reply

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

Answer by Bunny83 · Mar 27, 2014 at 02:09 AM

Ok, first as reference my GUI crash course.

What you should do is create a GUISkin and add a custom style at the bottom. You should create a small texture for the box background. Keep in mind that the texture's transparency is responsible if you can see through it (like the default box texture). The texture can be 3x3 splitted by setting top / left / bottom / right border values in the GUIStyle.

I would always recommend to use GUILayout instead of GUI. Your example would be something like this:

 var skin : GUISkin; // assign your skin in the inspector

 function DrawPhoto()
 {
     GUILayout.BeginArea(Rect(Screen.width/2-300, Screen.height/2-300, 1000, 600));
     GUILayout.BeginHorizontal("YourCustomStyleName");
     
     GUILayout.BeginVertical();
     GUILayout.FlexibleSpace();          // this will align the image at the bottom
     GUILayout.Label(AddPhoto);
     //GUILayout.FlexibleSpace();        // with this it would be centered
     GUILayout.EndVertical();
 
     GUILayout.BeginVertical();
     GUILayout.Space(50);
     GUILayout.Label(YourCaptionText, "AnotherCustomStyleForTheCaptionText");
     GUILayout.Label(YourDescriptionText, "CustomStyleForTheDescriptionText");
     GUILayout.EndVertical();
     
     GUILayout.EndHorizontal();
     if (GUI.Button(Rect(980,0,20,20),"X"))
     {
         showPhoto = false;
     }
     GUILayout.EndArea();
 }
 
 
 function OnGUI()
 {
     GUI.skin = skin;   // make unity use our custom skin
     if(showPhoto)
     {
         DrawPhoto();
     }
 }

You can do a lot with the GUIStyle setting in your GUISkin. You can even tweak the values at runtime in the editor and they'll keep their settings, so watch out.

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 StigC · Mar 27, 2014 at 07:37 AM 0
Share

Thank you, this looks just like the deal! Will definetly have look at the crash course ;)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer

How to display a characters "dialogue" when entering a collider? 1 Answer

How to script GUI Texture Window to see it in Script (Object's component) 1 Answer

Aligning an overlay to existing GUI elements 0 Answers

Create GUI Texture using GUI Layout 2 Answers


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