Script doesn't continue when i dont hit anything with raycast2D

So yeah. Maybe its just me thats tired or something. But in this code i’ve made here there is a wierd error(null reference exeption).

`public function Slash(){
var hit: RaycastHit2D = Physics2D.Raycast(transform.position, facingDir, SlashRange);

if(hit.transform.tag == "Enemy"){ //I cant attack when the raycast doesnt hit anything.... 
	Debug.Log("I hit the enemy");
}else{

Debug.Log("Didnt hit anything....");

}
anim.SetTrigger("Slash");
yield(WaitForSeconds(AttackTime));
anim.SetTrigger("Continue");

}

Please help.

You need to be checking if hit is not null - otherwise hit.transform in the if will be a null reference exception

if(hit != null && hit.transform.tag == "Enemy") {
    ...
 }