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 Tjheslin1 · Jun 01, 2014 at 03:03 PM · movementguitext

GUIText not following player

I have a 2d Player consisting of a Transform, Quad (Mesh Filter), Mesh Renderer, Rigidbody2D, BoxCollider2D and a script for player movement.

For the purpose of debugging, without having to use breakpoints, I'm trying to print info about the player on screen. I'm using a GUIText object, passing it to the script attached to the player and updating its text property each frame.

The issue is that the GUIText doesn't properly follow the player. It moves with the player but at a faster rate. When moving the player left and right the text does also but at a much faster rate, quickly disappearing off screen.

I have tried making the GUIText object a child of the player and have also tried setting its position to the players rigidbody position and tried setting it to the players transform position. All yield the same results of the text moving magnitudes higher relative to the players movement.

Any help would be greatly appreciated.

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
0
Best Answer

Answer by NickP_2 · Jun 01, 2014 at 03:13 PM

GUITexts do have a transform, but you don't have to use it like that.

UPDATE; DONT READ Read this: http://docs.unity3d.com/Manual/class-GuiTexture.html

When the position of the GUIText is x: 1, and y:1 it means it's at the upper right corner of your screen, x & y : 0.5f = center screen, and x & y: 0 = left lower corner of the screen.

To move it with the player, you would have to convert the players world position to a viewport position in code. So try this code, and attach the script to your main camera

 //drag the player's transform here in the inspector
 public transform player;
 //drag the guiText here in the inspector
 public GUIText debugGUIText;
 
 void Update()
 {
    debugGUIText.transform.position = camera.WorldToViewPortPoint(player.position);
 }


Didn't check for errors, hope it helps!

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 Tjheslin1 · Jun 01, 2014 at 04:00 PM 0
Share

Worked a treat! $$anonymous$$any thanks :D

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

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

Related Questions

Creating a castle-crasher-like Game [Need Help] 3 Answers

Moving 2D Sprite Object in Curve path. 4 Answers

How can I keep a global score updatable from multiple GameObjects 1 Answer

Rotate while moving forward 1 Answer

Move Object Using iTween 2 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