My enemy's damage doesn't work

Hi, I’m new in this exellent community :wink:
My name’s is Fabio “faek” Paccosi and I’m an Indie game developer from Rome.

I’ve a question. why the system of my enemy’s damage doesn’t work whit the player life script. I don’t understend why :?

Probably will be a stupid question, but it’s very important for my game :wink:

This is the enemiesAI script:

// Enemy AI
private var ismoving=false; 	// is moving the Enemy?
private var target : GameObject;	// Enemy´s Target
var enemyVelocity = 5;				// Enemy´s Velocity
var damage :int=5;                         // Enemy's Damage
var attakingVelocity = 1;			   // attack time rate
var collisionDistance = 1.5; 
var audioIdle : AudioSource;


function  Start(){
// set the target and starts to moving at start
target = GameObject.FindWithTag("Player");
ismoving = true;
}
function Update () {

//: if not moving, wait one second, else, if the enemy have a target, chase that target (player)
if(!ismoving)
{
	attakingVelocity += Time.deltaTime;
	if(attakingVelocity > 1)
	{
		ismoving=true;
		attakingVelocity = 0;

	}
}
else
{
if(target)
	ChasePlayer(target);

}

}


function ChasePlayer(target:GameObject)
{	
// look at target
		var direction =  target.transform.position - transform.position;
		direction.y=-10.0;
		var rotation = direction;

//rotate smoothly to the target´s direction
		transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(direction), 3 * Time.deltaTime);
		transform.eulerAngles = Vector3(0, transform.eulerAngles.y, 0);

// stablish the orientation
		var forward = transform.TransformDirection(Vector3.forward);

//Stablish the velocity variance depend on the target´s direction
		var speedModifier = Vector3.Dot(forward, direction.normalized);
		speedModifier = Mathf.Clamp01(speedModifier);

//if target reaches a certain distance between him and the player, hurts the player and stop moving, else, it continues moving
		if (Vector3.Distance(transform.position, target.transform.position) < collisionDistance) // Collision Distance is a var
		{
			ismoving=false;
		    DoDamage();
		}
		
		else
		{
			direction = forward * enemyVelocity * speedModifier;
			if(GetComponent (CharacterController))
				GetComponent (CharacterController).SimpleMove(direction);
			else
			{
				rigidbody.velocity=direction;
				rigidbody.velocity.y=-1;
			}
		}
	
	yield;
}
function DoDamage ()
{
	target.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver); 

}

And this is the PlayerLife script:

//Player's script for life and score.
//Player life and Score var must be use for GUI scripts

static var PlayerLife : int = 100;   //Base Player Life
static var score : int = 0;          //Base Player Score 
var SuondDie : AudioSource;       //Audio File for Player's die

function Update ()

{
	if(PlayerLife <= 0)
	
	{
	
		Destroy(this.gameObject);
		return;
	}
	
}
	

function ApplyDamage (damage : float) 

{
	PlayerLife -= damage;

	print (damage);
}

thanks to everyone.
Sorry for my bad English :sweat_smile:

Anyone can help me?

Sorry for this post, but it’s very important to me :wink:

what errors are you getting ?

No error, simply the enemy’s damage doesn’t damage the player :frowning:

then i suggest you debug your rpc call, see if it’s sending it and if the remote receives it.

Can you tell me how i do? :wink:

Thanks

dont know if this will help but you spelt sound wrong. u spelt it suond. Im net to but thats the error that i saw :slight_smile:

Try putting a print statement in the DoDamage function first:-

print("DoDamage gets called");

If it doesn’t get called, then work back to the “if” statement where the call is made and check the condition to make sure the collision distance is correct, etc. Using this basic approach, you can probably figure out where the error is happening.