It has rightly been said that the day without learning something new is a day that has gone waste.

First things First, Have you ever wondered about the games that are made based on the TRON movie? We see a some cool bikes with flashing trails following them. That is remarkably unique in its own way.

In terms of common language, we call them a WOW EFFECT, but coming in terms of UNity, It is a LineRenderer.

"The line renderer is used to draw free-floating lines in 3D space.

This class is a script interface for a line renderer component."

using UnityEngine;
using System.Collections;

public class LineScript : 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);
     }

}

So, another script will be attached on the cube which will move in a direction..

 //Cube script. Attach this script to a cube and give it a tag name "Player" via the inspector.
         bool canMove = false;
	// Update is called once per frame
	void Update () {
		if(Input.GetMouseButtonDown(0)){
             canMove = true;
			Invoke("StopMovement",4f);
        }
		if(canMove){
			transform.Translate(Vector3.right * Time.deltaTime * 10f);
		}
	}
        //Stop the movement of the cube.
        //So, The player will stop moving and you can see a pretty good trail.
        // If you want a fancy one, then attach a pretty decent material to it.
	void StopMovement(){
		canMove = false;
	}

So, after a lot of hard-work(Pheww) we're finally done with Line Renderer part. Let me show you a screen shot. Of course with a fancy material.

Click on the images given below to have a clear view, on what is going in here

Hope this will help you.

 

 

Post By:- Siddharth Verma