コード例 #1
0
    private void Empty()
    {
        _collider.enabled = false;
        _playerCharging   = false;
        _fuelComponent    = null;

        if (GameEventsManager.OnFuelStopCharging != null)
        {
            GameEventsManager.OnFuelStopCharging();
        }
    }
コード例 #2
0
    private void OnTriggerExit(Collider other)
    {
        _fuelComponent = other.GetComponent <FuelConsumptionComponent>();

        if (_fuelComponent != null)
        {
            _fuelComponent = null;

            _playerCharging = false;

            if (GameEventsManager.OnFuelStopCharging != null)
            {
                GameEventsManager.OnFuelStopCharging();
            }
        }
    }
コード例 #3
0
    private void Update()
    {
        if (!_playerCharging)
        {
            return;
        }

        if (_currentCharge <= 0)
        {
            return;
        }

        if (_fuelComponent == null)
        {
            return;
        }

        float amount = _chargingTimeStep * Time.deltaTime;

        _currentCharge -= amount;

        bool canContinueCharging = _fuelComponent.Charge(amount);

        // If fuel is full then stop charging
        if (!canContinueCharging)
        {
            _playerCharging = false;

            if (GameEventsManager.OnFuelStopCharging != null)
            {
                GameEventsManager.OnFuelStopCharging();
            }
        }

        // Checks if charge station has charge
        if (_currentCharge <= 0)
        {
            Empty();
        }
    }