About.

This script is used to draw free-floating lines in 3D space.

How To use this script.

  1. Create an empty GameObject.
  2. Rename it to “LineGO” or whichever you feel like its good for you.
  3. Attach this script to that gameObject in Editor.
  4. Attach a Line Renderer Component to that gameObject.
  5. (Components—>Effects—>Line Renderer).

Code:

using UnityEngine;
using System.Collections;

public class LineRendererScript : MonoBehaviour {
     /// The line renderer component that is attached to the gameObject..
     LineRenderer lineRenderer;
     /// The cube that we are finding in the scene. ///

     GameObject cube; // Use this for initialization
     void Start () {
         lineRenderer = gameObject.GetComponent<LineRenderer>();
         //the cube that is in the scene has beeen assigned the tag as a player.
         cube = GameObject.FindWithTag("Player");
         //It has two indexes by default. The initial point denotes the Index 0, and the
         //final point(of the line renderer) denotes the index 1
         lineRenderer.SetPosition(0, cube.transform.position);

         //Set the width of the line renderer.
         lineRenderer.SetWidth(0.5F, 0.5F);
     }

     void Update() {
        //the end position of the line will follow the player where ever it goes.
        //This is the effect that I am talking about.
        lineRenderer.SetPosition(1, cube.transform.position);
     }

}

Note :

  1. Since this scripts variables will not be accessible by any other GameObjects, hence class functions and variables are not mentioned specially.
  2. However, the uses of the variables/function in the code are properly commented.

 

 

Post By:- Siddharth Verma