Search Unity

How do I find the real-world transform of a point on canvas + a bug

Discussion in 'UGUI & TextMesh Pro' started by teh1archon, May 8, 2015.

  1. teh1archon

    teh1archon

    Joined:
    Nov 28, 2014
    Posts:
    12
    Hello,

    I'm making a game which is build entirely on uGUI and in one of its sections I need to draw lines (as stocks values that go up and down) from one side of the screen to the other (they don't take the whole screen height). Because GUI is rendered above anything else I cannot use overlay mode so I use screen-space instead for the main canvas that holds all the elements and above them/closer to the camera I use LineRenderer.
    The graphs are to be drawn inside a panel but when I try to get the min anchor and max anchor I get only the min anchor of the main canvas. How do I get the "real-world" co-ordinates of the canvas?

    I tried everything and it didn't work, not even making the panel itself a canvas (which is truly unnecessary) and even worse when I try to get the info of said canvas via "canvas.pixelRect.position" the editor crashes.

    What can I do?

    Best regards,
    Shay.
     
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    TO get the real world coordinates for UI elements, you simply need to use the ScreenSpacetoWorldSpace conversion routines against the camera that is rendering the UI (or vice versa)

    Alternatively, you can check out this community component for drawing lines in the UI system - http://forum.unity3d.com/threads/new-ui-and-line-drawing.253772/