Instantiating & Destroying GameObjects in Unity
Objective: Understand how to instantiate and destroy GameObjects in Unity .
First, in order for us to be able to Instantiate a GameObject, we need to have a reference of it, so we need to create a Prefab of that object.

Now that we have a copy of our GameObject, we are going to learn how to Instantiate it.
[SerializeField] private GameObject _laserPrefab;
We create a variable that is going to hold the reference of our GameObject that is going to be instantiated.

Now that we have a reference of our GameObject, we need to be able to Instantiate it. I’m going to set the default by pressing the Space Key.
if (Input.GetKeyDown(KeyCode.Space))
{
Instantiate(_laserPrefab, transform.position, Quaternion.identity);
}
This code above Instantiate a copy of our Prefab every time we press the space key. We have 3 parameters for our Instantiate method, which Prefab is going to be instantiated, the position of the GameObject being instantiated, and its rotation.
I’m setting as default the position that our player is currently in, and we don’t care for the rotation of the object, so we can set to Quaternion.identity to set to its default value.