shooting script wont damage enemy

i am making a zombie survival game and i ran into a problem that is when i shoot my gun using raycast at my enemy its should kill him but it does no damage until he is almost 2 feet away.

shooting script:


#pragma strict
var damage : int = 100;
var meleeaim : Transform;
var ammo = 15;
var clips = 10;

function Update() {
	if (Input.GetKey(KeyCode.LeftShift)) {
		animation.CrossFade("walking");
	}
if (Input.GetButtonDown("Fire1") && ammo >= 1) {
//	animation.Play("shoot");
	attackdamage();
 }
 if (ammo <= 0 && clips >= 1) {
 	reload();
 }	
if (animation.isPlaying == false) {
  animation.CrossFade("gunidel");
  }
//  if (Input.GetKey(KeyCode.LeftShift)) {
//  	animation.CrossFade("swordrun");
//  }
 if (Input.GetKeyUp(KeyCode.LeftShift)) {
 	animation.CrossFade("gunidel");
 }
}
function attackdamage() {
		var hit : RaycastHit;
	if (Physics.Raycast(meleeaim.transform.position, meleeaim.transform.TransformDirection(Vector3.forward), hit)) {
	hit.transform.SendMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
	}
}

function shoot() {
	ammo -= 1;
}	

function reload() {
	 	clips -= 1;
	 	ammo = 10;
}


enemy health:

#pragma strict
var damage : int = 100;
var meleeaim : Transform;
var ammo = 15;
var clips = 10;

function Update() {
	if (Input.GetKey(KeyCode.LeftShift)) {
		animation.CrossFade("walking");
	}
if (Input.GetButtonDown("Fire1") && ammo >= 1) {
//	animation.Play("shoot");
	attackdamage();
 }
 if (ammo <= 0 && clips >= 1) {
 	reload();
 }	
if (animation.isPlaying == false) {
  animation.CrossFade("gunidel");
  }
//  if (Input.GetKey(KeyCode.LeftShift)) {
//  	animation.CrossFade("swordrun");
//  }
 if (Input.GetKeyUp(KeyCode.LeftShift)) {
 	animation.CrossFade("gunidel");
 }
}
function attackdamage() {
		var hit : RaycastHit;
	if (Physics.Raycast(meleeaim.transform.position, meleeaim.transform.TransformDirection(Vector3.forward), hit)) {
	hit.transform.SendMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
	}
}

function shoot() {
	ammo -= 1;
}	

function reload() {
	 	clips -= 1;
	 	ammo = 10;
}

does anyone know how to fix this.


The third parameter of Physics.raycast is the distance and you’re putting the hit object in there. Try changing the third parameter to 1000 or a big number