Physics raycast not returning hit

SOLVED See below for what I did.
I am trying to add some line of sight check for my AI, but for some reason it won’t return if I hit the player or not.

var canSee = 0; //1 = can see, 0 = can't see.

function Update () { 
print(canSee);

var player = GameObject.FindWithTag("Player");
var hit : RaycastHit;
var rayDirection : Vector3 = player.transform.position - transform.position;

Debug.DrawRay  (transform.position, rayDirection, Color.white); //Shows it hits player fine when testing.

if (Physics.Raycast (transform.position, rayDirection, hit)) //This condition passes.
    {
        if (hit.transform == player) //Nothing, even when debug line shows it's targeting the player, culprit is here.
        {canSee = 1;} 
        else 
        {canSee = 0;} //This else statement fires.
    }

}//end of update.

Solution: I needed to use this: if (hit.transform.tag == “Player”) instead of if (hit.transform == player)

player.transform.position

if (hit.transform == player)

one of them is a gameObject and the other is a transform. You’re comparing a gameobject to a transform.

Yes, I’ve been confusing them for a long time. I still don’t entirely understand.

a gameObject is a container for holding related components.

a transform is a component which holds x,y,z,rotation information.

all gameObjects have a transform component since they all have to exist somewhere in the scene, other components (scripts, meshes, physics etc.) are optional. Despite all gameObjects having to have a transform component if you compare a gameObject container with a transform component you’ll get a “false” since they are different.

You basically asked “is this carrier bag the same as this can of beans?”

That’s what I basically figured, but when I need to move the transform of a gameobject, I need to tell the code what object I want to affect and affect the transform of it, so the need to work with both in the same line of execution is common, that’s what throws me off about the syntax.