Right now I have a variable called “punchdamage” that changes based on the player’s input, I know it works because I set it to display the variable’s value on the debug log, but when I try to subtract a variable, Molehealth, by the “punchdamage” value, it says that the value of “punchdamage” is 0,
This is my code for subtracting the Molehealth variable:
mlhealth.Molehealth = mlhealth.Molehealth - Combatmgr.punchdamage;
Also when I subtract the variable by a number, like 3f, it works.
Thank you so much in advanced!
try adding a debug log to check if its not null when you are doing the substraction:
mlhealth.Molehealth = mlhealth.Molehealth - Combatmgr.punchdamage;
Debug.log(Combatmgr.punchdamage);
and try to create a method that already recive the damage value:
public void take_damage(float damage){
mlhealth.Molehealth -= damage;
}
the thing is that you have to consider from what object you are calling or in this case doing the damage
also try making the variable static
hope this was usefull.,maybe try adding a debug log below in your code to see if its not null when you are calling it in that part of the script:
mlhealth.Molehealth = mlhealth.Molehealth - Combatmgr.punchdamage;
Debug.Log(Combatmgr.punchdamage);
try creating a method that requiers the value that you want to reduce
public void take_damage(float damage){
mlhealth.Molehealth -= damage;
}