• 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 Carousser · May 18, 2014 at 04:54 AM · guispritedraw

Drawing a sprite box and then displaying text over it

I'm trying to figure out how to draw a sprite and then display text over it. I want to do something like this alt text

Where I draw a sprite ontop of whatever is already in the background (and dimming the background) and then have configurable text ontop of it. My issue is the code to draw the image.

I'm using JS for my project if that helps at all. I tried looking in the references and around the GUI one's in particular, but couldn't find anything that seemed to fit my problem

Here is my current code

 var hit : RaycastHit;
 
 var menuOpen : boolean = false;
 
 function OnGUI () {
 
     if(menuOpen == true) {
         GUI.Label(Rect(Screen.width / 2,Screen.height / 2,Screen.width,Screen.height),
         "Line 1\nLine 2\nLine 3\nLine 4!");
     }
 }
 
 
 function Start () {
 
 }
 
 function Update () {
 
 
 if(Input.GetMouseButtonDown(0) &&
        collider.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), hit,
                         Mathf.Infinity)) {    
         menuOpen = true;            
                      
     }
 
 }
help.jpg (64.3 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 robertbu · May 18, 2014 at 07:18 AM 0
Share

Research:

  • GUI.Label()

  • GUIText

  • 3D Text/Text$$anonymous$$esh

The third one lives in world space and therefore can be aligned the easiest. GUIText lives in viewport space, so you can use Camera.WorldToViewportPoint() to convert.

avatar image Carousser · May 18, 2014 at 07:41 PM 0
Share

I ended up doing this function OnGUI () {

     if(menuOpen == true) {
         GUI.Label(Rect(0,0, Screen.width, Screen.height),"", "box");
         GUI.Label (Rect (Screen.width/4, Screen.height/4-50, windowToDisplay.width, windowToDisplay.height),
             windowToDisplay);
         
         // exit button
         if (GUI.Button (Rect (Screen.width/2 +150, Screen.height/4, exitToDisplay.width/4, exitToDisplay.height/4), exitToDisplay, invisibleStyle)) {
             Application.Quit();
         }
     }
 }

And it seems to work. Thanks

0 Replies

· Add your reply
  • Sort: 

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

A node in a childnode? 1 Answer

Draw a rotated image on GUI 1 Answer

Pressing "T" in the Sprite Editor trims the slice. It should only work when pressing "Shift+T". Please help 1 Answer

Render RenderTexture in OnGUI 0 Answers

Screenshot certain layers so it doesn't show GUI Button on the image?? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges