示例#1
0
 //will always drain until target value reached
 void Update()
 {
     if (!reachedTarget)
     {
         float perc = Time.deltaTime / timeToDrain;
         float diff = battery.totalCapacity * perc;
         battery.Sub(diff);
         if (battery.CompareCapacity(targetDrainLevel) < 1)
         {
             if (continuous)
             {
                 targetDrainLevel = battery.NextTargetEnergyLevel();
             }
             else
             {
                 reachedTarget = true;
                 battery.SetCapacity(targetDrainLevel);
                 StopDrain();
             }
         }
     }
 }