So I have this game where enemy units can get dots. (sofar only damage dots exist)
Those dots have a tickrate and a dotTimer float variable that counts down.
public interface IDot
{
public void DotEffect(Unit unit);
}
this is the interface so i can cicle through all dots in the unit and use DotEffect(Unit unit)
public class Dot : MonoBehaviour, IDot
{
public Element element;
public float dotTimer;
public float tickrate;
public float tickrateResetValue;
public virtual void DotEffect(Unit unit)
{
}
private void Update()
{
//Debug.Log("Update");
dotTimer -= Time.deltaTime;
//Debug.Log(timer);
tickrate -= Time.deltaTime;
}
}
this is the basic dot class that implements the interface
it also inherits from MonoBehaviour so i can use the update function and decrease the value of all the timers
public class DamageDot : Dot
{
public int damage;
public override void DotEffect(Unit unit)
{
//Debug.Log(timer);
if (tickrate <= 0)
{
//Debug.Log("TICK");
tickrate = tickrateResetValue;
DamageCalculator.DamageCalculationForDot(unit, this);
}
//Debug.Log(dotTimer);
if (dotTimer <= 0)
{
Debug.Log("timer <= 0");
unit.dots.Remove(this);
Destroy(this.gameObject);
}
}
}
this is the damagedot class… the section of → if(tickrate <= 0) works and the unit takes dot damage.
but the if(dotTimer <= 0) just doesent get executed. Im about to burst into tears. I have wasted all night on this and cant get it to work.
Some dots get the value below 0 and delete themselfs as expected… but some just go below 0 and keep going.
Pls help