Day 7: Creating behavior for a laser

Objective: I want to be able to create movement for my lasers.

First we need to make a script for our laser prefab. Then we need to make a variable for speed so we can change how fast the lasers move.

Once the variable is created we need to change the position on the laser prefab from the player and make sure it continuously moves forward. To do that we need to access the transform, then position, and then write Vector3.up times the speed variable and Time.DeltaTime since we want the laser to move at a speed per second not per frame.

Then we need the laser to spawn from the players position so we need to instantiate the laser prefab from the player script. So we need to write an if statement for when the space bar is pressed to create the prefab from the players position.

The Quaternion uses the rotation of the object and since we’re working in 2D we just use identity to keep the same rotation.

I am hard working Game development student learning as much about game development and unity as possible.