public float ReceiveEnergy() {
float amountToReturn = 0;
if (powerSupply.getIsEnergySupplied()) { //hub supplying energy.
//get how much energy to add based on average per sec.
float energyToAdd = powerSupply.getAvgUsePerSec() * Time.deltaTime * scale.getTimeScale();
if (powerSupply.getIsOn()) { //if on.
powerSupply.addTotalUse(energyToAdd);
amountToReturn = energyToAdd;
}
//and charge battery as well.
int numB = getNumBatteries();
for (int i=0; i<numB; i++) {
Battery b = powerSupply.getBatteryList()[i];
if (!b.getIsFull()) {
//found a not full battery.. charge this one and break.. so you don't charge the others too.
b.setEnergy(b.getCurEnergy() + energyToAdd);
break;
}
}
}
return amountToReturn;
}