コード例 #1
0
 void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.tag == "Player" && gameManager.isGameRunning)
     {
         SoundManager.PlaySound(SoundManager.Sound.Collect);
         fuelManager.AddFuel(Random.Range(0, 50));
     }
     Destroy(gameObject);
 }
コード例 #2
0
 private void OnTriggerStay2D(Collider2D coll)
 {
     if (coll.tag == "Player")
     {
         theFuelManager.AddFuel(fuelToGive * Time.deltaTime);
         theFuelManager.refueling      = true;
         thePlayerController.refueling = true;
     }
 }
コード例 #3
0
 public void NewGame()
 {
     existingMap = GameObject.Find("map_0");
     if (!existingMap)
     {
         Instantiate(map_0, mapStartingPosition, transform.rotation);
     }
     transform.position = new Vector3(0, (float)startingPosition, 0);
     theLifesManager.ResetLifes();
     theFuelManager.AddFuel(100);
     respawnPoint.transform.position        = new Vector3(0, (float)startingPosition, 0);
     mapDestructionPoint.transform.position = new Vector3(0, (float)destructionPointStartingPosition, 0);
 }
コード例 #4
0
 void OnTriggerEnter(Collider col)
 {
     if (col.GetComponent <PlayerController>())
     {
         soundsController.PlayFuelTankPick();
         ChangePosition();
         FuelManager.AddFuel(fuel);
     }
     else
     {
         ChangePosition();
     }
 }
コード例 #5
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());
                }
            }
        }
    }