Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Using Camera Position as Line Renderer Point

Discussion in 'AR' started by hamishryan6, Jul 28, 2020.

  1. hamishryan6


    Jul 27, 2020
    Hi All,

    I am trying to render a line using the following points:
    Point 1: Camera Position (constantly updating)
    Point 2: Defined in Script (nothing in particular)

    I want this line to act as a path for a user to walk towards in order to reach the end of the line. I have only just started using Unity and cannot find a way to reference the Camera's position as a line's point. Below is the code I have so far.

    public class PathRenderer : MonoBehaviour
    private LineRenderer lineRend;
    private Vector2 cameraPos;
    GameObject cam;

    // Start is called before the first frame update
    void Start()
    cam = GameObject.Find("ARCamera");
    lineRend = GetComponent<LineRenderer>();
    lineRend.positionCount = 2;

    // Update is called once per frame
    void Update()
    lineRend.SetPosition(0, new Vector3(cameraPos.x, cameraPos.y, 0));