Reputation: 21
i have a little problem. Im trying that when you shoot the enemy its lose health, so i have 2 scripts, one in the camera with the damage because its an fps, and other in the enemy with the health. The problem is that im trying to subtract the damage to the health, but that mesagge appears in the code, in target.takeDamage(damage) Thank you
My code:
CAMERA
void shoot(){
RaycastHit hit;
//Raycast desde la camara, hacia delante, la informacion del raycast y con el rango que le demos
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) {
Debug.Log(hit.transform.name);
//A quien hemos impactado (), y lo llamamos target
EnemyBase target = hit.transform.GetComponent<EnemyBase>();
//Comprobamos si lo que hemos impactado es un enemigo
if(target !=null){
//Si lo es le mandamos la variable de daño
target.TakeDamage(damage);
}
}
}
ENEMY:
public void TakeDamage() {
vidaEnemigo -= damage;
if(vidaEnemigo <= 0f){
Die();
}
}
void Die(){
Destroy(gameObject);
}
Upvotes: 0
Views: 2067
Reputation: 9821
Your TakeDamage
function doesn't accept any parameters but you're trying to pass one in. Give it a parameter (I'm guessing you want an int
or a float
here):
public void TakeDamage(int damage) {
vidaEnemigo -= damage;
if(vidaEnemigo <= 0f){
Die();
}
Upvotes: 1