I looked it up and I saw a lot of people having the same problem. Unfortunately the fixes are not interchangeable, and what worked for them is not working for me.
I have a simply script to divide a variable by a certain amount and stores it into another variable, and each time x happens, the stored amount gets subtracted from the original variable. So if x happens the certain amount of times that the original variable was divided by, the original variable’s value will become 0. Unfortunately if the original variable’s value is an uneven number, I store the divided value into another float, it won’t have enough decimals to amount to 0, which is why I have to to use a decimal. Here is the script:
public float Speed = 6;
private decimal SpeedSubstractionValue;
private bool immobile;
private int amountOfLegs;
void Start () {
foreach (Transform child in this.transform)
{
if(child.name == "Leg")
amountOfLegs++;
}
SpeedSubstractionValue = ((decimal)Speed / amountOfLegs);
}
public void TakeHit()
{
if(((decimal)Speed - SpeedSubstractionValue) >= 0)
{
(decimal)Speed = (decimal)Speed - SpeedSubstractionValue;
if(Speed <= 0)
immobile = true;
}
}
}
All this does is make so that when you hit all the legs on the object, the object’s speed will become 0. Unfortunately this line: (decimal)Speed = (decimal)Speed - SpeedSubstractionValue; gives me the error in my title.