Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

GUI Using WorldToScreenPoint is Out of Control

Discussion in 'Getting Started' started by GUIUsingWorldToScreenPointisOutofControl, Jan 19, 2023.

  1. GUIUsingWorldToScreenPointisOutofControl

    GUIUsingWorldToScreenPointisOutofControl

    Joined:
    Feb 1, 2022
    Posts:
    1
    I want to have a GUI float over a Gameobject using WorldToScreenPoint. However, I am experiencing strange behavior with the GUI. I assume that this is due to the character's movement. I have already tried using Screen Space - Overlay and have keep a constant pixel size.


    Code (CSharp):
    1. void Update() {
    2.  
    3.         Vector3 loc = transform.position;
    4.  
    5.         Collider[] colliders = Physics.OverlapSphere(loc,Radius);
    6.  
    7.         foreach (Collider hit in colliders){
    8.  
    9.             if(hit.gameObject.tag == "Player"){
    10.  
    11.                 pressgui.transform.position = Camera.main.WorldToScreenPoint(transform.position);
    12.  
    13.             }
    14.  
    15.         }
    16.  
    17.     }