4

I'm using Vectrosity to draw a line between my 3D GameObject and a UI element. However, I'm struggling to convert the RectTransform position data so I can pass it to the drawline function.

I've been experimenting with getting the RectTransform position of my desired UI elements and trying to draw a line between them. However, this doesn't work. When I change the code to make use of normal 3D objects in my scene, the line appears as intended. This is the code that I currently have been playing with:

  void Start ()
{

  //  points[0] = image.rectTransform.transform.position;
  //  points[1] = image2.rectTransform.transform.position;

    points[0] = obj1.transform.position;
    points[1] = obj2.transform.position;

    line = new VectorLine("Line", points, mat, 2.0f, LineType.Continuous);
    VectorLine.canvas.sortingOrder = 1;
    VectorLine.SetCanvasCamera(Camera.main);

}

// Update is called once per frame
void Update () {
    line.Draw();

}

The first commented out line get the positions of my 2 UI objects fine, but nothing appears on the screen. The uncommented out line work fine. Is there something I'm doing wrong here?

All of the above is done in a 3D scene. I'll be having my camera orbit, rotate and zoom around the 3D object and would like the line to remain consistent

Fattie
  • 27,874
  • 70
  • 431
  • 719
Sean
  • 897
  • 4
  • 20
  • 42
  • updated my original question – Sean Mar 11 '16 at 13:36
  • 1
    it s'a real pain in the bum to do this .. `RectTransformUtility` is your friend! – Fattie Mar 11 '16 at 13:46
  • This is a great question, @Sean - I never have a frickin clue the best way to map from UI to the normal game scene. It's a great pity there is so much clutter on SO in this tag. Hopefully your question gets plenty of attention. I will add a bounty once the time passes. – Fattie Mar 11 '16 at 14:48

0 Answers0