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 Inan-Evin · Apr 13, 2012 at 04:36 PM · guitexturecornerbottom

GUI Texture on bottom left/right corners

Hello everyone. I want to make a 2D texture in the bottom right of the screen. But if I adjust it within the inspector, the position of the 2D Gui Texture can be different according to the resolutions. So I know that it can be arranged with code and suitable for every resolution. I have a code that makes a GUI label on the right bottom but I couldn't figure out how to make it for drawing a texture.

GUI.Label (Rect(Screen.width - 200,Screen.height-35,200,80),"something: ");

this is what I use for creating a text in bottom right corner. I want the same thing for the texture. Can someone lead me to the right way for doing this ? Thanks :)

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

3 Replies

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

Answer by gregzo · Apr 13, 2012 at 04:42 PM

Careful! GUITextures pixelInset properties have their origin at the bottom left of the screen. Just adapt the code you have for GUI.Label accordingly, using GUITexture.pixelInset.x and y. I hope I'm clear!

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 AlucardJay · Apr 13, 2012 at 04:48 PM 1
Share

just at a guess , I think @T-Pr is after something like this :

 var myBoxTexture : Texture2D;
 
 function OnGUI()
 {
     GUI.Box (Rect(Screen.width - 200,Screen.height-35,200,80), myBoxTexture);
     GUI.Label (Rect(Screen.width - 200,Screen.height-35,200,80), "something: ");
 }

drag-and-drop your image into the Inspector where it says 'myBoxTexture' =]

avatar image Inan-Evin · Apr 13, 2012 at 05:19 PM 0
Share

well that's almost what I wanted, thanks for hat :). But is there a way of doing it without drawing a box ? Or making the box invisible, because the size of the texture is adjusted according to the size of the box.

avatar image AlucardJay · Apr 13, 2012 at 05:26 PM 1
Share

I havn't done anything like that myself (am a noob really), gregzo or someone can probably answer that. All I can suggest is have a look at the Unity Scripting Reference and hopefully you shall find a method there that you want.

http://unity3d.com/support/documentation/ScriptReference/GUI.DrawTexture.html

http://unity3d.com/support/documentation/ScriptReference/GUI.DrawTextureWithTexCoords.html

http://unity3d.com/support/documentation/ScriptReference/GUI.html

avatar image gregzo · Apr 13, 2012 at 06:11 PM 0
Share

GUITexture is what you're after. In the import settings of your image, select GUI, then in the scene, create GUITexture. Drag and drop your image, reset the transform's position, pixelInset properties will be correct! @alucardj I'm just a noob+, ;)

avatar image AlucardJay · Apr 14, 2012 at 03:08 AM 1
Share

probably a bit late =] , but I just learned how to do this :

 // Draws a texture in the left corner of the screen.
 // The texture is drawn in a window 60x60 pixels.
 // The source texture is given an aspect ratio of 10x1
 // and scaled to fit in the 60x60 rectangle.  Because
 // the aspect ratio is preserved, the texture will fit
 // inside a 60x10 pixel area of the screen rectangle.
 var aTexture : Texture;

 function OnGUI() 
 {
     // check there is a texture to use
     if(!aTexture){
         Debug.LogError("Assign a Texture in the inspector.");
         return;
     }

     GUI.DrawTexture(Rect(10,10,60,60), aTexture, Scale$$anonymous$$ode.ScaleToFit, true, 0); // aspect ratio is 0 , true image scale displayed

     GUI.DrawTexture(Rect(150,10,60,60), aTexture, Scale$$anonymous$$ode.ScaleToFit, false, 0.0); // no alphablend (no transparency)

     GUI.DrawTexture(Rect(80,10,60,60), aTexture, Scale$$anonymous$$ode.ScaleToFit, true, 10.0); // apect of image is changed to ( 60 : 6 ), image is centred to the Rect

     GUI.DrawTexture(Rect(10,70,90,90), aTexture, Scale$$anonymous$$ode.ScaleToFit, true, 0); // image is scaled to the size of the Rect given
 }
Show more comments
avatar image
0

Answer by Malikoguzghost · Jun 03, 2014 at 07:57 AM

maybe you can do it by

function OnGUI() { GUI.backgroundcolor = Color.clear; GUI.Box (Rect(Screen.width - 200,Screen.height-35,200,80), myBoxTexture); GUI.Label (Rect(Screen.width - 200,Screen.height-35,200,80), "something: "); }

:)

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
avatar image
0

Answer by Tranoze · Jan 10, 2018 at 10:11 AM

Use GUIStyle and change it alignment.

         guiStyle = new GUIStyle(GUI.skin.label);
         guiStyle.font = myFont;
         guiStyle.fontSize = 48; //change the font size
         guiStyle.normal.textColor = Color.white;

         guiStyle.alignment = TextAnchor.LowerRight;
         

         GUI.Label(Rect, "Text", guiStyle);
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

7 People are following this question.

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

Related Questions

GUITexture Button? 1 Answer

rotating GUI texture by angle 2 Answers

Sprites and minmizing memory usage 1 Answer

How to place/add a HD image/picture in background of my game? 0 Answers

GUILayer hit doesn't work. Any help? 0 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