Firing the projectile

Return to the Shooter script we have been working on so far by double-clicking its icon in the Project view, or by selecting it in the Project view and clicking the Open button at the top of the Inspector.

Now we will make use of the bullet variable we declared earlier, using it as a reference to the particular object we wish to instantiate. As soon as the object is created from our stored prefab, we will apply a force to it in order to fire it at the wall in our scene. Go to the following line:

transform.Translate(h, v, 0); 

After this line, within the Update() function in your script, add the following code:

if(Input.GetButtonUp("Fire1")){ } 

This if statement listens for the key applied to the Input button named Fire1 to be released. By default, this is mapped to the left Ctrl key or left mouse button, but you can change this to a different key by adjusting the settings in the Input Manager (Edit | Project Settings | Input).