How to add line renderer in unity

This post is about using line renderer in your unity game.

What is line renderer?

The Line Renderer component takes two or more points in 3D space and draws a straight line between each one.

The line is always continuous; if you need to draw two or more completely separate lines, you should use multiple GameObjects, each with its own Line Renderer.

The Line Renderer does not render one-pixel-wide lines. It renders billboard lines (polygons that always face the camera) that have a width in world units and can be textured. It uses the same algorithm for line rendering as the Trail Renderer.

Video Tutorial


Ask or Request for anything you want in the comments below and I will help you 😀

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DrawLine : MonoBehaviour {
    public GameObject P1;
    public GameObject P2;

    LineRenderer gunLine;

	// Use this for initialization
	void Awake()
    {
        gunLine = GetComponent<LineRenderer>();
        gunLine.enabled = true;
        //Draw();
    }
	
	// Update is called once per frame
	void Update ()
    {
        Draw();
    }

    public void Draw()
    {        
            gunLine.SetPosition(0, P1.transform.position);
            gunLine.SetPosition(1, P2.transform.position);
           
    }
}