Raycast not working - Need help

Hello folks.

I have some trouble with this Raycast script. I admit, I’m not that good at coding yet, so I thought I would seek some help here.
This is what I want the script to do:

1: Detect if the player is currently looking at a bottle (Could be any game object)
2: Print that you’re looking at the object if you are.
3: If you are looking at an object, and press the mouse button 0, Destroy the object and print a message

Now, this is what I have so far:

var distance = 10;

function Update () 
{
	
	Screen.showCursor = false;
	
	var dir = transform.TransformDirection(Vector3.forward);
	var hit : RaycastHit;
	
	Debug.DrawRay(transform.position, dir * distance, Color.blue);
	
	if( Physics.Raycast( transform.position, dir, hit, distance ) ){
	
		if( hit.collider.gameObject.tag == "Quest Bottle" ){
		
			print("You are looking at a bottle!");
			
			if(Input.GetKey(KeyCode.Mouse0)){
			
				Destroy(hit.collider.name);
				print("Picked up a Bottle!");
			
			}
		
		}
	
	}

}

However, this doesn’t work. I guess one of the problems could be that I cannot see the ray in-game, therefore, I don’t know where to “look” to pick up the object. Secondly, I’m not sure this is actually how it should be written.

Anybody has some inputs?

I don’t know what the transformdirection does, but I don’t think you need it. (edit: deleted a question that didn’t make sense)

Try the code below, see if it works.

var distance = 10;

function Update () 
{
    Screen.showCursor = false;

    var dir = transform.forward;

    var hit : RaycastHit;    

    Debug.DrawRay(transform.position, dir * distance, Color.blue);    

    if( Physics.Raycast( transform.position, dir , hit, distance ) ){  

        if( hit.collider.gameObject.tag == "Quest Bottle" ){        

            print("You are looking at a bottle!");            

            if(Input.GetKey(KeyCode.Mouse0)){            

                Destroy(hit.collider.name);

                print("Picked up a Bottle!");            

            }    
        }
    }
}

transform.TransformDirection(Vector3.forward) is the same as transform.forward. This isn’t something you can do:

Destroy(hit.collider.name);

Instead it should be

Destroy(hit.collider.gameObject);

You can see the Debug.DrawRay in the scene view, as well as the game view if gizmos are turned on.

–Eric