why does this also return a game object

function CanSeeTarget() :boolean // return true or false
{
// Return false if it is too far way( that is, more than 15)
if(Vector3.Distance(transform.position, target.position) > 15){
return false;
}
var hit :RaycastHit;
// cast a line from enemy to the player and retrieve some information about it
if(Physics.Linecast(transform.position, target.position, hit))
{
//what this line do? simply return the player? it was suppose to return ture or false if there was nothing between them, so why is this returning the player?
or is it returning true if the hit is the player? PLEASE, I JUST CAN’T UNDERSTAND THIS…
return hit.transform == target;
}
// otherwise return true if there is no collider between the enemy and the player
else if(!Physics.Linecast(transform.position, target.position)){
return true;
}
return false;
}

Try setting that as a boolean before the return statement. bool crazyThing = (hit.transform == target) and see if that is storing what you expect. Try debbugging it in Mono or use Debug.Log(crazyThing);

Are you missing the .transform after target in the second if?

function CanSeeTarget() : boolean
{
	var result : boolean = false;
	
    if(Vector3.Distance(transform.position, target.position) > 15)
    {
    	result = false;
    }
    
    var hit :RaycastHit;
    if(Physics.Linecast(transform.position, target.position, hit))
	{              
    	result = hit.transform == target.transform;
    }    
    else if(!Physics.Linecast(transform.position, target.position))
    {
    	result = true;
    }
    
    return result;
}

the code is working properly in fact I got it from 3d motive, i’m just trying to figure out what each line does, and I couldn’t get this line: result = hit.transform == target.transform;

Is it testing if the hit matches our player, what? Cuz the function is supposed to return a boolean, so what is this checking for?