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 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.

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

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

A node in a childnode? 1 Answer

Create big city for car game? 2 Answers

Tracking Down GUI Errors 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