void UpdateEnergy() { if (search.Finished() && isAtTarget && !isMoving) { if (currentEnergyExpanded < totalEnergy) { float increment = ((float)totalEnergy / search.GetNumberOfNodesExpanded() * regenRate); currentEnergyExpanded = Mathf.Min((currentEnergyExpanded + increment), totalEnergy); } if (currentForce < totalEnergy) { float increment = ((float)totalEnergy / search.GetMaxListSize() * regenRate); currentForce = Mathf.Min((currentForce + increment), totalEnergy); } } else { if (search.GetRunning()) { currentEnergyExpanded = totalEnergy - (int)(search.GetNumberOfNodesExpanded() / updateEnergyExpandedInterval); currentForce = totalEnergy - ((int)search.GetMaxListSize() / updateForceInterval); if (currentEnergyExpanded <= 0 || currentForce <= 0) { search.setRunning(false); isDead = true; MakeDead((currentEnergyExpanded <= 0) ? Energies.Expanded : Energies.Force); } } } UpdateEnergyBars(healthForce, (int)currentForce, Color.blue); UpdateEnergyBars(healthExpandedBar, (int)currentEnergyExpanded, Color.yellow); }