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 Stagnant · Jun 08, 2013 at 11:22 AM · gameobjectguitext

No position variable for GUIText()?

 public class OverHeadEffects: MonoBehaviour {
 
     GUIText text;
 
     public OverHeadEffects(Vector3 pos)
     {
         this.gameObject.transform.position = new Vector3(pos.x, pos.y+10f, pos.z);
     }
     
 
 
 
     public void setTextColor(string text, string color = "#000000"){
         this.text = new GUIText();
         this.text.richText = true;
         this.text.text = "<color=\"" + color + "\">" + text + "</color>";
     }
     public void setText(string text){
         this.text = new GUIText();
         this.text.text = text;
     }
     public string getText() { return this.text.text; }
 }

...I'm guessing there's something I'm missing about the way things interact in Unity. Basically, what I'm trying to make is a class which, when initialized by the character object, creates itself slightly above the character/enemies, the prints out a text string (in this case, it's supposed to appear to show damage taken/dealt). However, GuiText has no transform variable, so I guess I'm a little confused. Do I need to attach it to an existing GameObject as a variable? How would I best do this?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by robertbu · Jun 08, 2013 at 02:06 PM

GUIText does have a transform. You can access it by:

 text.gameObject.transform.position = new Vector3(0.5, 0.5, 0.0);

But there is an issue with respect to placing GUIText adjacent to a game object. GUIText lives in Screen space. Most game objects live in World space. Screen coordinates start at (0,0) in the lower left of the screen and go to (1,1) in the upper right of the screen. In order to make the conversion you can use [Camera.WorldToScreenPoint()][1]. So you would do something like:

 Vector3 v3ScreenPos = Camera.main.WorldToScreenPoint(v3WorldPosition);
 text.gameObject.transform.position = v3ScreenPos;


[1]: http://docs.unity3d.com/Documentation/ScriptReference/Camera.WorldToScreenPoint.html

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 DricoJD · Jun 08, 2013 at 01:58 PM

I would not use Gui-Text as they can only really function very well inside of a GUI Texture (Atlas). Try using 3D Text it is the same as a GUI text, but moveable.

Comment
Add comment · Show 1 · 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 Owen-Reynolds · Jun 08, 2013 at 06:33 PM 0
Share

The big difference is "lives in the world" vs. "lives in screen." A 3DText naturally shrinks with perspective and can be viewed from any angle. Oddly, 3DText is not normally hidden by things in front of it, but you can make it that way.

Both can have problems with looking bad, which can be fixed with a little work.

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

16 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

Related Questions

Multiple Targets 1 Answer

audio.Play() not working? 6 Answers

GetComponent, int error, if statement, problem. 1 Answer

how to make fixed guiText ? 0 Answers

Access guiText from other object. 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