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 JChiu · Sep 30, 2013 at 06:31 AM · guiglitchviewporttoworldpoint

GUI flickering on screen for certain GUI

In my game I have two different type of GUI running all the time, one for displaying the player's health and the other displaying enemies' health. Those that display the enemies one are fine but the one for the player keeps flickering up and down. They are both using this same script below:

public class GUIFollow : MonoBehaviour {

 public float offest;
 public Transform target;

 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
     
     Vector3 pos = target.position + offest * Vector3.up;
     transform.position = Camera.main.WorldToViewportPoint(pos);
     
 
 }

}

Is this a glitch?

Comment
Add comment · Show 5
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 Professor Snake · Sep 30, 2013 at 08:22 AM 0
Share

Unless i misunderstood, i don't see any of the GUI code here. Could you include it in your question?

avatar image robertbu · Sep 30, 2013 at 08:28 AM 0
Share

@Professor Snake - considering that he is mapping to viewport space, he is likely using a GUITexture or a GUIText.

avatar image jakovd · Sep 30, 2013 at 08:36 AM 0
Share

I suppose you need to store the position above the player in viewport coordinates to another variable, not the transform.position. Transform is for 3D world coordinates, and what you get with WorldToViewportPoint is not the same type of Vector3. So, store it in another variable, don't override the transform.position with this new value. Then, use this new variable in your OnGUI method to draw the health label on that position.

By the way, it would be better if you would use WorldToScreenPoint method.

avatar image JChiu · Sep 30, 2013 at 09:46 AM 0
Share

Just to make things clear, the script is attach to GUIText and GUITexture.

avatar image JChiu · Oct 01, 2013 at 04:52 AM 0
Share

The problem is now fixed, however using WorldToScreenPoint is not displaying the GUIText and GuiTexture at all. It seem that (using the ViewPortPoint $$anonymous$$ethod) when I checked Apply Root $$anonymous$$otion (from the target transform object) in the Animator it fixed it.

Now I would like to know in a logical sense as in why does the Root $$anonymous$$otion check box will affect it?

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

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

GUI is too sensitive 1 Answer

Unity 5 UI Text Glitch (illegible characters) 0 Answers

UI working fine in editor but glitched in standalone builds 1 Answer

Script variables resetting on play 0 Answers

Camera.main.ViewportToWorldPoint not working like expected. 1 Answer


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