I have been learning a new method of programming. I have been programming many years and am recently finding out there is a better method in general via abstract classes.
My question is how to convert a small section of my code so i can understand how this works entirely. So far i could only figure out how to do 1 part:
public abstract class Water
{
public abstract string GetString(double AmountToAdd);
}
public class AddTotalWater : Water
{
public double TotalWater;
public override string GetString(double AmountToAdd)
{
TotalWater += AmountToAdd;
if (TotalWater > 999999)
return TotalWater.ToString(Globals.ScientificNotationFormatter);
else
return TotalWater.ToString();
}
}
and use it with:
TotalWater.text = AddTotalWater.GetString(amountToAdd);
I would just like some guidance to learn how to do this fully. Is this the proper way to do this to begin with?
This is the nested nightmare I have currently that i want to convert:
public void DetermineWaterValues()
{
if (Time.deltaTime < TotalWaterProductionTime)
{
double tempWaterTime = waterCounter += Time.deltaTime;
if (tempWaterTime > TotalWaterProductionTime)
{
tempWaterTime = TotalWaterProductionTime;
waterCounter = 0;
WaterProgressBar.fillAmount = 0;
TotalWater.text = AddTotalWater.GetString(amountToAdd);
}
else
{
if (TotalWaterProductionTime >= 0.1)
WaterProgressBar.fillAmount = (float)(tempWaterTime / TotalWaterProductionTime);
else
WaterProgressBar.fillAmount = 1;
}
}
else
{
WaterProgressBar.fillAmount = 1;
TotalWater.text = AddTotalWater.GetString(amountToAdd);
}
}
It's quite complicated to figure out how to do this properly. This is the way i did it for over 10 years heh...