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. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

WorldToGUIPoint help

Discussion in 'Immediate Mode GUI (IMGUI)' started by SgtWombat, May 19, 2009.

  1. SgtWombat

    SgtWombat

    Joined:
    May 19, 2009
    Posts:
    11
    Hi, I'm having trouble setting up the WorldToGUIPoint, as the documentation does not provide an example and I could find no help on the forums or internet.

    This is the code that I made, but I can't figure out the initial setup:

    Code (csharp):
    1. function OnGUI() {
    2.    
    3.    var nodeGUI: HandleUtility;
    4.    
    5.    var node = GameObject.Find("node0");
    6.  
    7.    var nodeScript = node.GetComponent("NodeScript");
    8.    var nodeLoc = nodeGUI.WorldToGUIPoint(nodeScript.nodeLoc);
    9.    var bonus = nodeScript.nodeValue.ToString();
    10.    
    11.    GUI.Label(Rect(nodeLoc.x, nodeLoc.y, 100, 20), bonus);
    12.  
    13. }

    How would I correctly set up the nodeGUI and nodeLoc variables?
     
  2. SgtWombat

    SgtWombat

    Joined:
    May 19, 2009
    Posts:
    11
    I figured out a different way of doing it...

    Since the script is attached to the camera, I removed the nodeGUI variable and changed

    Code (csharp):
    1. var nodeLoc = nodeGUI.WorldToGUIPoint(nodeTwo.nodeLoc);
    to

    Code (csharp):
    1. var nodeLoc = camera.WorldToScreenPoint(nodeTwo.nodeLoc);
     
  3. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Sorry for being late to the game here, but I'm glad you sorted this out. We need to tidy up a number of scripting reference entries, especially some of these GUI APIs in particular.
     
  4. earthcrosser

    earthcrosser

    Joined:
    Oct 13, 2010
    Posts:
    121
    hi
    I was dealing with this issue too: here is the script I'm using and it works great. I found I had to make an adjustment to the y value to get the position I wanted