This script used to work... and now suddenly it doesent work anymore... Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class HPregen : Ability { public float healpercent; public float tickrate; public override void AbilityEffect(Unit unit) { if(timer >= tickrate) { timer = 0; int healamount = (int)((unit.baseHP / 100) * healpercent); Debug.Log(healamount); if(healamount <= 0) { healamount = 1; } unit.currentHP += healamount; if(unit.currentHP > unit.baseHP) { unit.currentHP = unit.baseHP; } unit.UpdateHealthbar(); } } } The Debug.Log(healamount); is always 0
Before someone else pops in with a whole lot of tips on debugging, look at line 15 and decide "what would make that result in 0?" In general, when doing math on computers, especially with integers but even with floats, you want to do multiplies before divides.
I added 2 debugs -> the math should work, wtf is happening how could i change this calculation to make it work Code (CSharp): Debug.Log(unit.baseHP); Debug.Log(healpercent); (47 / 100) * 10 should be more than 0
(47/100) is always going to be 0 if those are integers That's what @halley is pointing out. So for percentages, multiply first, THEN divide, then cast back to int EDIT: in related news, (100/47) is always going to be 2, if those are integers
So try some variations. Does moving healpercent to the front help? Do removing some parentheses help? Does multiplying by healpercent first help?