laser2d-documentation

LASER 2D

Download

web version of the doc - Recommended.

 Verssion : 0.06 
 Updated : December 2017 
 Developer : Shohanur Rahaman
 Contact : shohan4556@gmail.com 
 web : techshohan.me

Features

How To Use

  1. Getting Started
  2. Changing Laser Color
  3. Understanding Inspector Variables
  4. Using Four Directional Laser
  5. Modify Code
    1. How to Add Enemy Damage
    2. Modify Input
  6. Tips
  7. More Features is Coming Soon

Getting Started

The easiest to way to see Use Laser2D create a Parent Gameobject (that could be player/ship sprite) then drag the Prefab and make it child of the parent object. Add the Sprite Light material to the enemy gameobject. Play the game and Click the Right Mouse Button.

Getting Started

Changing Laser Color

To Change a Laser Color go through the child object > find the Laser Glow gameobject and change the sprite color.

Changing Laser Color

Understanding Inspector Variables

Inspector

Using Four Directional Laser

The easiest way to use Four directional laser is using Prefab there are four prefabs L2D-Top, L2D-Down, L2D-Left & L2D-Right you can use any of them. There is another way is Changing the Laser Direction.

Top-Down

How to Add Enemy Damage

To give damage on Enemy gameobject create a tag name as Enemy and add it to the enemy object. Edit the code inside the Update method.

 /*-------------------- Enemy Damage -------------------- */
     if (hit.collider.tag == "Enemy") {
      hit.collider.gameObject.GetComponent<L2DEnemyHealth().giveDamage(laserDamage);
   }
 /*------------------------------------------------------ */

Tips : For better performance you can cache the EnemyHealth script inside Start method.

Modify Input

To modify input go through the LaserBeam script and find the FireLaser function you can find there the input code. Its easy to change the code. Here is an example, assumes that you have a script Myscript you can simply do it like this from Myscript

	public LaserBeam laserbeam; // drag the LaserBeam gameobject
	void Start()
	{
		if(laserbeam==null){
		   laserbeam = 	Gameobject.FindObjectOfType<LaserBeam>();
		}
	}
	
	void Update()
	{
	    if(	Input.GetButtonDown(keyCode.Space){
		 laserbeam.FireLaser();   
	    }
	}

Note : Don’t forget to comment out the FireLaser method form the LaserBeam script.

Tips