Adding the wrong amount, cant figure it out...

Hi,

for some reason the wrong amount is being added.

I have:

minerHoldings.cashHarvested = gemHarvested.gemWorthStart;

which gives me the amount from the gem, say 100.

then I when I try to add this amount, it gives me some weird amount like 4,700.

function AddCash(){
	minerHoldings.cashHoldingAmount += minerHoldings.cashHarvested;
}

if I use:

minerHoldings.cashHarvested += gemHarvested.gemWorthStart;

this also gives the wrong amount.

I have tried other ways but keep failing, any ideas?

Thanks.

var mineBot: MineBotAI;
var minerHoldings: MovementMiner;

function OnTriggerEnter(other : Collider){
	if(other.gameObject.tag == "Gem"){
		other.gameObject.SendMessage("StartHarvesting", SendMessageOptions.DontRequireReceiver);
		mineBot.SendMessage("MinerOnTargetNow", SendMessageOptions.DontRequireReceiver);
	}
}

function OnTriggerStay(other : Collider){
	if(other.gameObject.tag == "Gem"){
	
		var gemHarvested: Gem = other.gameObject.GetComponent(Gem);
		
		if(gemHarvested.gemWorthStart >= gemHarvested.gemWorthMax){
			mineBot.SendMessage("MinerNoTarget", SendMessageOptions.DontRequireReceiver);
			AddCash();
		}
		
		minerHoldings.cashHarvested = gemHarvested.gemWorthStart;
	}
}

function OnTriggerExit(other : Collider){
	if(other.gameObject.tag == "Gem"){
		other.gameObject.SendMessage("StopHarvesting", SendMessageOptions.DontRequireReceiver);
		mineBot.SendMessage("MinerNoTarget", SendMessageOptions.DontRequireReceiver);
	}
}

function AddCash(){
	minerHoldings.cashHoldingAmount += minerHoldings.cashHarvested;
}

You’re adding the amount per frame as long as the 2 objects are colliding each other. You should add a timer so it adds over time as long as the 2 objects are colliding.

Yes that is what I want because while it is over the gem it extracts/harvests it value over time.

This is kind of hard to explain…

I have a miner that has a max limit of 2000 cash amount it can hold, when it gets to a gem it harvests it…

Say the gem has a value of 500, it will harvest 500 from it over time and when it is finished it moves on to the next gem. I want the 500 to then be stored in the miner, so its limit will now only be 1500.

But when it gets to the next gem, and starts harvest, the miner amount sets to 0 because the gem value starts at 0 and over time gets to its value.

So its basically resetting the Miners amount it had harvested.

This here is what makes it set to 0, the gems starting value:

minerHoldings.cashHarvested = gemHarvested.gemWorthStart;

After harvest, (cashHarvested = 500) I then want to add it to cashHoldingAmount.

Instead of adding 500 like it should… It adds something like 2,400 04 4,800 something wierd.

function Update(){	
	if(finishedHarvesting){
		AddCash();
		finishedHarvesting = false;
	}
}

function AddCash(){
	cashHoldingAmount += cashHarvested;
}