Пример #1
0
    private IEnumerator WhileObjectInTrigger(GameObject player) //energy transferred linearly with time
    {
        PackCharger pack = player.GetComponentInChildren <PackCharger>();

        while (inUse) //If the player is still using this skylight
        {
            float amount         = transferRate * Time.deltaTime;
            bool  transferFailed = false;

            if (pack != null)
            {
                if (pack.inOutputMode)
                {
                    transferFailed = ReceiveCharge(pack, amount);
                }
                else
                {
                    transferFailed = OutputCharge(pack, amount);
                }
            }

            if (transferFailed)
            {
                yield break;
            }

            yield return(null);
        }
    }
Пример #2
0
    private bool ReceiveCharge(PackCharger pack, float amount) //returns true if pack failed to output charge
    {
        if (pack.GetCharge() < 0)
        {
            Debug.Log("Pack empty!");
            return(true);
        }

        chargeLeft += amount;
        pack.ChargePack(-amount);

        return(false);
    }
Пример #3
0
    private bool OutputCharge(PackCharger pack, float amount) //returns true if skylight failed to output charge
    {
        if (chargeLeft < 0)
        {
            Debug.Log("Skylight closed!");
            return(true);
        }

        chargeLeft -= amount;
        pack.ChargePack(amount);

        return(false);
    }