HillClimb/Assets/Scripts/FuelManager.cs
2023-01-22 15:59:13 +05:30

37 lines
859 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FuelManager : MonoBehaviour
{
[Range(0f,100f)]
public float FuelLevel;
public float[] FuelConsumptionLevels;
public float FuelConsumption = 1;
public static FuelManager instance {get; private set;}
public RectTransform fuelNeedle;
public float fuelNeedleMax = 66;
void Awake(){
instance= this;
FuelConsumption = FuelConsumptionLevels[DataManager.FuelLevel];
}
void Update()
{
if(FuelLevel >0){
FuelLevel-=Time.deltaTime * FuelConsumption;
}else{
GameManager.GameOver();
}
fuelNeedle.eulerAngles = new Vector3(0,0, fuelNeedleMax - ((FuelLevel / 100f) * (fuelNeedleMax *2)));
}
public void Refill(){
FuelLevel = 100;
}
}