Learn to code By Making 2.5 D Space shooter
Objective: Implement Laser Behavior
In order to do this we need to understand this the behavior of any game object it going to have its own unique script.
The first step is to create a script for Laser behavior and drag it to laser prefab.
Inside our laser script we need to move the laser as soon it created, we move the laser first by accessing the game object by transform then Translate the laser.
This code will move the laser 1 unit per second
Wee need to increase our laser speed by create a laser speed variable and multiply with our Vector3 Translation.
When we fire a laser we need to clean our laser because if we constantly fire our laser go accumulate on hierarchy our game will freeze because it will eat our memory especially if build our game form mobile.so lets destroy the laser when pass the screen on.
If you notice our Laser Instantiated inside our player we want to spawn our laser above.
We does this by adding new Vector in the position of Instantiating.
In order to see clear if our laser instantiated on top lets add Debug.Break(); this code will make our to pause as soon it stat to spawn the laser to visual if we instantiate on top.
I hope enjoy today article
Suleiman