示例#1
0
    private void Update()
    {
        if (isInside)
        {
            float fuelToBuy = playerFuel.GetMissingFuel();
            int   cost      = Mathf.CeilToInt(fuelToBuy);
            StationsText.SetText("PRESS F TO REFUEL\nCOST: $" + cost);
        }

        if (PlayerGO == null)
        {
            PlayerGO = GameManager.GetCurrentPlayer();
            if (PlayerGO == null)
            {
                return;
            }
            playerFuel = PlayerGO.GetComponent <FuelManager>();
        }

        if (isInside && Input.GetKeyDown(KeyCode.F))
        {
            float fuelToBuy = playerFuel.GetMissingFuel();
            int   cost      = Mathf.CeilToInt(fuelToBuy);
            if (cost > 0 && playerMoney.GetMoney() > 0)
            {
                float perc = (float)playerMoney.GetMoney() / cost;
                AudioSource.PlayClipAtPoint(GameManager.Instance.CoinPickupSound, PlayerGO.transform.position);
                if (playerMoney.GetMoney() >= cost)
                {
                    playerFuel.FillFuel();
                    playerMoney.DecreaseMoney(cost);
                }
                else if (playerMoney.GetMoney() > 0)
                {
                    playerFuel.AddFuel(fuelToBuy * perc);
                    playerMoney.DecreaseMoney(playerMoney.GetMoney());
                }
            }
        }
    }