how can i refere to a taged object in Raycasthit ?

when i run the scene with this code and i’m neer the door taged “door” i have an error:
NullReferenceException: Object reference not set to an instance of an object
(i’m sure it’s taged correctly i used the tag in other script)

function Update () {

	var hit:RaycastHit;
	
	if(Physics.Raycast(transform.position,transform.forward,5)){
		if(hit.collider.gameObject.tag == "door"){
		
		        hit.collider.gameObject.animation.Play("ouvrir");

		}
	}
}

You need to use version that passes out hit info to assign the hit to the hit variable.

Check the documentation.

where u using hit

var hit:RaycastHit;
     
    if(Physics.Raycast(transform.position,transform.forward,hit)){
    if(hit.collider.gameObject.tag == "door"){
     
    hit.collider.gameObject.animation.Play("ouvrir");
     
    }
    }
    }