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 Rgalaxy · Jan 08, 2014 at 03:49 PM · guiimagecustomguistyle

[Closed]Custom Image On Gui.Box

Hello, i want to ask about how to insert a custom image i create to the GUI.Box?

as far as i do, the code is like this

 function OnGUI(){
     var judul : String;
     var asd : Texture;
 
     GUI.Box(Rect((Screen.width-(Screen.width/4*3))/2,
                     (Screen.height-(Screen.height/4*3))/2,
                     Screen.width/4*3, Screen.height/4*3),asd);
 }

i create a fair good amount of Gui Rect Box.. but i still dont understand how to change the Black background of the GUI.Box into the Images i want, i found out on Unity Documentation, it comes out like this..

static function Box(position: Rect, text: string): void;

static function Box(position: Rect, image: Texture): void;

static function Box(position: Rect, content: GUIContent): void;

static function Box(position: Rect, text: string, style: GUIStyle): void;

static function Box(position: Rect, image: Texture, style: GUIStyle): void;

static function Box(position: Rect, content: GUIContent, style: GUIStyle): void;

but there is no example to how inserting new image.. could anybody teach me how to do it?

EDIT : I've been searching about this, but some use GUI Skin, and i don't quite understand about that, do i need to use that? or i could do this by code instead?

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
2
Best Answer Wiki

Answer by JVaughan · Jan 08, 2014 at 03:59 PM

Where you see this:

 Static function Box(position: Rect, image: Texture): void. 

What this is saying that you can specify a screen space size and position with a Rect object and Texture image to fill the box instead of the default black transparent image.

So first you need to specify a Texture in the script that you can associate an image with. In C# that would look like this.

 public Texture2D myGUITexture;

Assign your GUI texture in the Inspector. Then in the script where you call GUI.Box reference your texture. Assuming you have a 192X64 texture stuck in the upper right corner at 5 percent of the screen the code would look like this in C#:

 void OnGUI (){
     GUI.Box(new Rect( Screen.Width*0.05f, Screen.Height*0.05f, 192, 64), myGUITexture);
 }
Comment
Add comment · Show 6 · 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 ArkaneX · Jan 08, 2014 at 04:04 PM 0
Share

Or in short form - move the line

 var asd : Texture;

outside of OnGUI function, and then assign the texture in the inspector.

avatar image Rgalaxy · Jan 08, 2014 at 04:06 PM 0
Share

aw, thanks, my code doesn't show my Texture on Inspector, because i put the var asd : Texture; inside the function, now it's already show up..

but i have some problem, which i could not arrange the size of the picture shown on GUI.Box? is there any way, i want to just call that image and the size is like the calculation above?

@ArkaneX just see your post. thanks, it's right, it was my fault.. but for the next problem could u help to solve it?

avatar image JVaughan · Jan 08, 2014 at 04:39 PM 0
Share

GUI.Box is always scale to fit, so if you want it to be a specific size specify it in pixels. If you want to draw a a GUI item with more options you need to use GUI.drawTexture ins$$anonymous$$d. Here is an example:

 GUI.DrawTexture(new Rect(screenPos.x,invertedCursorHeight,32,32),cursorTexture,Scale$$anonymous$$ode.ScaleToFit,true);

And if you could mark my first answer as correct it would be very appreciated!

avatar image Rgalaxy · Jan 08, 2014 at 04:49 PM 0
Share

yeah, i use GUI.DrawTexture, but why the images so blurry? is there anyway to make it better but not by changing the whole image into new larger image?

because, if i use Plane ins$$anonymous$$d, the images is so clear..

this is when i use Plane alt text and, this is when i use GUI.DrawTexture alt text

capture.png (441.7 kB)
capture.png (399.1 kB)
avatar image Rgalaxy · Jan 08, 2014 at 04:54 PM 0
Share

nvm, i found out, to change the Texture Type of the image on Image Inspector, change it to Texture Type "GUI" and it becomes crytal clear..

Question answered and Closed.. Thanks @JVaughan and @ArkaneX

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

20 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

Related Questions

Hover state doesn't work on slider with custom styles 0 Answers

GUI.Toolbar with different images for each button using GUIStyle 1 Answer

GUI Skin Custom textures in C# 2 Answers

Matching the size of UI elements with that of world objects 0 Answers

Custom Material Editor 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