"Player" tag collider from other GameObject?

I have this script attached to a GameObject but I need it to work on the GameObject with the “Player” tag. Why is the player variable not working when it collides with the “Wood” tag?

function OnControllerColliderHit(hit : ControllerColliderHit) {
    
    	var player = GameObject.FindWithTag("Player");
    
    	if(player.collider.gameObject.tag == "Wood") {
    		WalkWood();
    	}
    }

player.collider.gameObject.tag is the same as player.tag, or simply “Player”!

If you want to detect the type of the object the player is on, attach the script to the player and look at the hit object’s tag in the hit structure:

function OnControllerColliderHit(hit : ControllerColliderHit) {
  if (hit.gameObject.tag == "Wood") {
    WalkWood();
  }
}

But be aware that OnControllerColliderHit events occur all the time due to the collisions between the CharacterController and the ground, thus the function WalkWood will be called almost every physics cycle while the player is over an object tagged “Wood”.