Basic Shooting Game

i have created first person controller and gun is the child of the main camera of first person. I have created prefab game object which i have spawn at different location. Now i want to target this prefab object using my gun.

I have refered this tutorial for my basic start. Now i want to shoot this cube game object with mu first person controller gun. So what should i code to make target.?

Some of the coding i have written but with this it is not hitting these cubes.

Here is my code:

var shotSound: AudioClip; // drag a shot sound here, if any

// the PickupController component of the 'PickupSpawnPoints' GameObject
private var pickupController:PickupController;
function Awake()
{
    // retrieve the PickupSpawnPoints gameObject
    var pickupSpawnPoints:GameObject = gameObject.Find("PickupSpawnPoints");
     
    // and then retreive the PickupController Component of the above PickupSpawnPoints gameObject
    pickupController = pickupSpawnPoints.GetComponent("PickupController");
}
 
function Update(){
  if (Input.GetKey(KeyCode.Space)) {

      Shoot();
 	 }
} 

function Shoot(){
	if (shotSound) audio.PlayOneShot(shotSound); // play the shot sound
   	var hit: RaycastHit;
	var ray : Ray = Camera.main.ViewportPointToRay (Vector3(0.5,0.5,0));
	 
	if (Physics.Raycast (ray ,hit , 200))
	{
	    //var rot = Quaternion.FromToRotation(Vector3.up, hit.normal);
	 	Debug.DrawLine (ray.origin, hit.point);
	    if (hit.transfer.tag == "Pickup"){ // if enemy hit...
	       pickupController.Collected(hit.transfer.gameObject);
	       
    	}
    	
	}	   
}

I am very new in unity and still learning concepts and scripting in unity.
so please help me to target my game object. Thanx for your help and support in advance.

you probably need to add a public variable for your target. Something like this:

var target : GameObject;

// or this depending on your choice

var target : Transform;

then you can drag your target onto that variable in the editor and access it in the script

Good Luck!