I'm working in a AI script, and i have made the following function to check if the enemy can see the player.
function CanSeePlayer(){
var hit : RaycastHit;
var rayDirection = playerObject.transform.position - transform.position;
if (Physics.Raycast (Seeker.transform.position, rayDirection, hit)) {
if (hit.transform.tag == "Player") {
Debug.Log("Can see player");
return true;
}else{
Debug.Log("Can not see player");
return false;
}
}
}
If i put this code outside of the function and in the script it self, it works fine.
But when i try to access the function like this:
if(!CanSeePlayer){
Debug.Log("I cant see the player")
}
The script dosent work, and the Debug command dosent get run, even though it should.