- Home /
Question by
ikazrima · Oct 06, 2015 at 11:57 AM ·
uigameobjectlinerenderer
Line renderer from UI to 3D GameObject
Hi,
I would like to draw a line between a UI element to a 3D game object.
I tried something like this, and some other variations
void Update ()
{
Vector2 pos;
RectTransformUtility.ScreenPointToLocalPointInRectangle(CanvasRect, target.position, null, out pos);
startPos = CanvasRect.transform.TransformPoint(pos);
LineRenderer lr = gameObject.GetComponent<LineRenderer>();
lr.SetPosition(0, startPos);
lr.SetPosition(1, endPos);
}
But of course it gives weird results, like it appears correct in the editor but not in the game itself.
What's the best way to draw a line between a UI element (screen space overlay) to a game object (world space)?
Thanks
Comment