62 lines
2.0 KiB
C#
62 lines
2.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
|
|
public class FuelSelector : MonoBehaviour
|
|
{
|
|
[SerializeField] private TextMeshProUGUI fuelNameText;
|
|
[SerializeField] private Button leftButton;
|
|
[SerializeField] private Button rightButton;
|
|
[SerializeField] private Transform flame1;
|
|
[SerializeField] private Transform flame2;
|
|
[SerializeField] private Transform flame3;
|
|
|
|
private int _currentIndex = 0;
|
|
|
|
private readonly string[] _names = { "10%", "25%", "50%", "75%", "100%" };
|
|
|
|
private readonly float[] _maxHeights = { 500f, 8000f, 50000f, 200000f, 800000f };
|
|
|
|
private readonly Vector3[] _scales =
|
|
{
|
|
new Vector3(0.4f, 0.12f, 0.4f),
|
|
new Vector3(0.65f, 0.20f, 0.65f),
|
|
new Vector3(0.90f, 0.30f, 0.90f),
|
|
new Vector3(1.15f, 0.40f, 1.15f),
|
|
new Vector3(1.40f, 0.52f, 1.40f)
|
|
};
|
|
|
|
private void Start()
|
|
{
|
|
if (leftButton != null) leftButton.onClick.AddListener(PrevFuel);
|
|
if (rightButton != null) rightButton.onClick.AddListener(NextFuel);
|
|
ApplyFuel(0);
|
|
}
|
|
|
|
private void ApplyFuel(int index)
|
|
{
|
|
if (fuelNameText != null) fuelNameText.text = _names[index];
|
|
if (flame1 != null) flame1.localScale = _scales[index];
|
|
if (flame2 != null) flame2.localScale = _scales[index];
|
|
if (flame3 != null) flame3.localScale = _scales[index];
|
|
if (leftButton != null) leftButton.interactable = index > 0;
|
|
if (rightButton != null) rightButton.interactable = index < _names.Length - 1;
|
|
}
|
|
|
|
private void NextFuel()
|
|
{
|
|
if (_currentIndex < _names.Length - 1) { _currentIndex++; ApplyFuel(_currentIndex); }
|
|
}
|
|
|
|
private void PrevFuel()
|
|
{
|
|
if (_currentIndex > 0) { _currentIndex--; ApplyFuel(_currentIndex); }
|
|
}
|
|
|
|
public int GetFuelLevel() => _currentIndex;
|
|
public float GetMaxHeight() => _maxHeights[_currentIndex];
|
|
public string GetFuelName() => _names[_currentIndex];
|
|
}
|