damage test not working?

    public void DealDamage(int dmg, int hpTarget, int currentTargetHealth)
    {
        currentTargetHealth = hpTarget - dmg;
    }

    public void PlayerAttack()
    {
        DealDamage(playerData[0].strStat, playerData[0].hpStat, playerData[0].hpStat);
        //Debug.Log(playerData[0].hpStat);
    }

So not sure what i’m doing wrong, but while testing this, the player hp isnt dropping when i debug this. I have PlayerAttack() hooked up to a ui button.

Primitive values aren’t passed by reference, but by value. So your third parameter in particular, it just passes in whatever the value of hpStart is, but that’s not in any way linked back to the hpStat member.
You probably should rewrite it to use a return value:

public int DealDamage(int dmg, int hpTraget) {
return hpTarget - dmg;
}
public void PlayerAttack() {
playerData[0].hpStat = DealDamage(playerData[0].strStat, playerData[0].hpStat);
}
1 Like

OHHHH okay, thank you! I just learned something lol