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 Yaako92 · Apr 27, 2014 at 02:58 PM · gui

The gui box is overloaded with the background

Hi everyone, I want to make the background of the inventory.

I created the gui box but unable to make the background like the image above. Once I tried, the gui box is overloaded with the background.

Here is the image:

alt text

On the above image, I did not apply the background yet. But when I applied the background, it become like image below:

alt text

How do I make the background to the behind? So the gui box is not overloaded with the background, it is like the background become the holder for the gui box?

Here is the code that I am using:

 void OnGUI()
 {
 GUISkin skin;
 
 private Texture2D inventoryBackground;
 
 inventoryBackground = Resources.Load<Texture2D>("Inventory Background"); // Inventory Background is the black background shown in the second image.
 
 Rect backgroundInventory = new Rect((Screen.width / 3) - 5, (Screen.height / 3) - 80, 450, 450);

 // I tried to make the GUISkin on Unity and apply the Inventory Background Texture on it and named it with Inventory Skin, but it says unable to find Inventory Skin
 
 GUI.Box(backgroundInventory, string.Empty, GUI.skin.GetStyle("Inventory Skin")); 
 
 // I used either this code below or above (GUI.Box) to make the background, but still, the gui box that I have created is overloaded with the background
 
 GUI.DrawTexture(backgroundInventory, inventoryBackground); 
 
 // This code below is to create the empty gui box based on the slotsX and slotsY
 
 int slotsX = 10;
 int slotsY = 10;
 
         for (int y = 0; y < slotsY; y++)
         {
             for (int x = 0; x < slotsX; x++)
             {
                 Rect slotRect = new Rect(x * 40 + (Screen.width / 3) + 25, y * 40 + (Screen.height / 3) - 50, 35, 35);
                 
                 GUI.Box(slotRect, string.Empty);
             }
         }

Your answer much appreciated!

Thank you so much!

capture2.png (2.2 kB)
capture.png (6.0 kB)
Comment
Add comment · Show 2
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 · Apr 27, 2014 at 03:28 PM 0
Share

The word overloaded means something rather different to us, just an fyi. Try flipping the two

avatar image Yaako92 · Apr 27, 2014 at 04:43 PM 0
Share

Sorry, I didn't get what you mean sir. Which one and should I flip?

1 Reply

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

Answer by FLASHDENMARK · Apr 27, 2014 at 03:50 PM

The problem is rather simple. You are drawing the background after drawing your inventory slots. This means that the background is drawn in front and not in the back, which is what you want.

Simply change the rendering order.

UPDATE:

 public Texture2D inventoryBackground; //Assign through the Inspector
 public Rect backgroundInventory;
 
 void Awake () {     
         backgroundInventory = new Rect((Screen.width / 3) - 5, (Screen.height / 3) - 80, 450, 450);
 }
 
 
 void OnGUI () {          
     GUI.DrawTexture(backgroundInventory, inventoryBackground); 
           
     int slotsX = 10;
     int slotsY = 10;
  
     for (int y = 0; y < slotsY; y++)
     {
         for (int x = 0; x < slotsX; x++)
         {
             Rect slotRect = new Rect(x * 40 + (Screen.width / 3) + 25, y * 40 + (Screen.height / 3) - 50, 35, 35);
      
             GUI.Box(slotRect, GUIContent.none);
         }
     }
 }
Comment
Add comment · Show 7 · 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 Yaako92 · Apr 27, 2014 at 04:41 PM 0
Share

Thank you sir. But when I changed the code like your answer. I am still got the result like the image above (blank image) when the GUI.Box or GUI.DrawTexture is called after many boxes was called. Is the problem is the texture itself?

I want to be like this (Link):

Image

avatar image FLASHDENMARK · Apr 27, 2014 at 05:34 PM 0
Share

A blank image like the image not rendering at all? Or it rendering in front?

Please have a look at updated answer.

avatar image Yaako92 · Apr 27, 2014 at 05:58 PM 0
Share

No, it render sir, but rendering in front.

I have added the item to the GUI.Box with and without background image and modify the code as you mention on updated answer. This image link will show you:

Without Background With Background

avatar image FLASHDENMARK · Apr 27, 2014 at 06:18 PM 0
Share

Are you completely sure that is rendering the texture in front?

Since that is a black background you cannot see the GUI boxes. Try changing the background texture to a white texture.

avatar image Yaako92 · Apr 27, 2014 at 06:29 PM 0
Share

I have decrease the opacity of the background to 50% and this is how it looks like sir:

alt text

Still, this background still rendering in front

capture.png (18.3 kB)
Show more comments

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

How to make a Hover event on GUI.Button 6 Answers

Unity 4.6 GUI vs Unity 4.5 GUI 1 Answer

how can i create vertical graph chart(bar) with GUI texture and effect to the bar? 0 Answers

White Edge on Transparent Texture 2 Answers

Temperature Script? 3 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