I’ve been trying to solve this problem all evening. I’m either really stupid or doing something completely wrong.
I have 2 floats, Amount and Access defined as below:
float amount = UnityEngine.Random.Range(0f, 10000000f);
float access = (float)Math.Round(UnityEngine.Random.Range(0.1f, 1f), 1);
These are used to create a new mineral deposit class
MineralDeposit mineralDeposit = new MineralDeposit(mineralType, amount, access);
MineralDeposit.cs
public class MineralDeposit
{
public MineralDeposit(MineralType despositType, float amountInDesposit, float access)
{
DespositType = despositType;
Amount = amountInDesposit;
Access = access;
}
public float Access { get; private set; }
public float Amount { get; private set; }
public MineralType DespositType { get; private set; }
public float RemoveFromDeposit(float amountToRemove)
{
if (amountToRemove > Amount)
{
Amount = 0;
return amountToRemove;
}
else
{
UnityEngine.Debug.Log(Amount);
Amount -= amountToRemove;
return amountToRemove;
}
}
}
The RemoveFromDeposit method is called like this:
float amountMined = minerals.RemoveFromDeposit(minerals.Access / 10f);
The method is returning correct but the issue is the Amount variable in the MineralDeposit class isn’t subtracting. It works if I use RemoveFromDeposit(minerals.Access * 10f);
but whenever it gets a smallish float passed it’s refusing to subtract.
I’m am doing something blatantly wrong here?
Thanks.