Control Your Fire!
Well, we’ve created our laser prefab and now we need a laser script. How else are we gonna get it to move? So let’s create another C# Script within our Scripts folder and drag it over to our Laser prefab:
Now that the script is inside our Laser Prefab, let’s figure out how to get it moving! So to start off let’s create a variable for the movement speed of the laser.
Now that we’ve got that set up, we get the laser to shoot from the cube by using Vector3.up, which is shorthand for
“new Vector3(0, 1, 0)”
Now let’s move on to getting this baby to pew!
Let’s head into our Player Script: create our variables, assign our Laser Prefab, create our method and set it up in our void Update()
So, our variables have been created, our method is created and assigned, and before I forgot I assigned our laser prefab.
Let’s now start making our pseudo-code:
“If we hit our fire key, which we’ll be assigned to Spacebar, we will fire our laser.”
Time.time — time that has passed each frame
Instatiate — to provide an instance of or concrete evidence in support of (a theory, concept, claim, or the like)
Now, we hit save and…