LineRendererScript

June 27, 2013 | Rishabh Agrawal | General

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


THE AUTHORRishabh Agrawal

Rishabh Agrawal is the founder of Creatiosoft, a company focused on creating high-quality software for the iGaming industry, specialising in poker and card games. With years of experience, Rishabh is dedicated to delivering engaging and user-friendly gaming experiences. Through this blog, he shares his passion and insights to help readers understand the latest trends and advancements in iGaming.

Recent Posts

The Future of Mobile Gaming: What to Expect in the Next 5 Years

Over the years, mobile gaming has seen amazing development and innovation utilized by the game development company in India. It…
06 Jun 2023 Rishabh Agrawal

How Do I Get Started With NFT Gaming?

The popularity of the NFT game has created a different fan base. There was a time when games were a…
18 Jul 2022 Rishabh Agrawal

What Are The Top Trends in NFT Marketplace 2022?

The NFTs are the new engaging and revolutionary technology across the globe. Though, these non-fungible tokens appeared for the first…
09 Jun 2022 Rishabh Agrawal