public int will always stay 0
Hi, I am making a 2D shooting game and now in the progress of making a taking damage system. I have two scripts, "projectile" and "Enemy". Here are my codes
public int power;
if (hitInfo.collider.CompareTag("Enemy"))
{
Debug.Log("ENEMY HIT"); //successful
Debug.Log(power); //prints out 0
hitInfo.collider.GetComponent<Enemy>().TakeDamage(power);
}
public void TakeDamage(int power)
{
health = health - power; //Always doing health - 0 since power equals 0
}
So when a projectile hits enemy collider, it calls the TakeDamage function and in my Enemy script, it updates the health.
I've checked calling the TakeDamage function was successful, but the problem is that the public int power will always stay 0 causing no damage to the enemy. I tried changing it to 1 through the inspector but didn't change.
I tried setting the int power to 0 by writing public int power = 1; but still printed out 0
I want to change int power through the inspector, please help!
Your answer
Follow this Question
Related Questions
How to use a public int in another script? 1 Answer
public int variable not updated in inspector for two scenes in Unity 0 Answers
Cannot convert float to int? 1 Answer
Playerpref Saving Lag 1 Answer