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 husbandofemily · Mar 23, 2013 at 12:01 PM · guitextviewporttoworldpoint

GUIText viewporttoworldpoint makes text disappear.

Hi All. I've created a GUIText, whoch defaults to the center of my screen. I know I can move it around using the Pixel Offset, but I want it to be consistant regardless of the aspect ratio, so I added the following script to another gameObject, referencing the GUI:

 var clipDisplay : GUIText;
 var clipDisplayX = 0.5;
 var clipDisplayY = 0.5;
 var thisCam : Camera;
 
 function Update()
 {
 clipDisplay.guiText.transform.position = thisCam.ViewportToWorldPoint(Vector3(clipDisplayX, clipDisplayY, 0));
 }

The clipDisplayX and Y are set to 0.5, the idea being I can adjust them in the Inspector window to find the position I need. But when I add the ViewportToWorldPoint line, the GUIText disappears from the game.

I know it'll be just somewhere out of sight, but I can't find it. I've adjusted the X and Y values, and added the thisCam variable to ensure it's using the right camera. I've even tried changing the font and material out of desperation, but no avail. I'm sure it's something simple I'm missing...

If I comment out that one line, the GUI comes back to the center. Strange. I'm out of ideas, can anybody help please?

Cheers

Ian

Comment
Add comment · Show 3
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 whydoidoit · Mar 23, 2013 at 12:06 PM 1
Share

GUIText is placed at a viewport position already isn't it? Certainly is for me on U4. So just setting it's transform.position to (0.5,0.5,0) puts it in the middle of the screen.

avatar image Owen-Reynolds · Mar 23, 2013 at 01:55 PM 0
Share

3DText is placed using worldView coords, so you may be using code meant for one of them (ex: I want this on the ground where it appears top-centered at (0.5, 0.9) in the screen. What (x,y,z) of the terrain is currently there?)

A common use for this type of thing is on a GUIText is worldToViewPort. You know you want "Blood drinker" near the ogre's head, and need the 0-1/0-1 screen coords.

avatar image husbandofemily · Mar 23, 2013 at 04:14 PM 0
Share

Thanks guys, like I say below, I must've been using code from an old answer from this site, as it was marked correct and voted up. Plain old clipDisplay.guiText.transform.position = Vector3(clipDisplayX, clipDisplayY, 0); works fine. Thanks again :-)

1 Reply

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

Answer by husbandofemily · Mar 23, 2013 at 12:14 PM

Whydoidoit - you're spot on. I must be using an old answer from Unity 3x.... Top Banana. I'd rate your answer right but it's in the comments section ;-) Thanks a lot.

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

12 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

Related Questions

[JS] How to display an Int variable through a GUI Text?? [Resolved] 2 Answers

How do I reference a UI text in Unity 5? (JS) 2 Answers

Score wont show 0 Answers

How to create a review of previous updates 1 Answer

Code behind 'Camera.ViewportPointToRay'? 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