65 lines
1.7 KiB
C#
65 lines
1.7 KiB
C#
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
using TMPro;
|
|
using UnityEngine.UI;
|
|
|
|
public class ThrottleController : MonoBehaviour
|
|
{
|
|
[Header("Input")]
|
|
public InputActionReference throttleAction; // Your Input Action reference
|
|
|
|
[Header("Throttle Settings")]
|
|
public float rampSpeed = 1f; // Units per second
|
|
|
|
[Header("References")]
|
|
public MainEngine mainEngine; // Reference to your engine script
|
|
// Referance to TextMeshPro Throttle slider
|
|
public Slider throttleDisplay; // Reference to UI Slider component
|
|
|
|
void OnEnable()
|
|
{
|
|
if (throttleAction != null)
|
|
{
|
|
throttleAction.action.Enable();
|
|
Debug.Log("Throttle action enabled.");
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("Throttle action reference is not set!");
|
|
}
|
|
}
|
|
|
|
void OnDisable()
|
|
{
|
|
if (throttleAction != null)
|
|
throttleAction.action.Disable();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (throttleAction == null || mainEngine == null)
|
|
return;
|
|
|
|
// Read input (-1, 0, +1)
|
|
float input = throttleAction.action.ReadValue<float>();
|
|
|
|
// Debug what the input is reading
|
|
//Debug.Log($"Input value: {input}");
|
|
|
|
// Calculate new throttle target
|
|
float target = mainEngine.throttleInput + input * rampSpeed * Time.deltaTime;
|
|
|
|
// Clamp between 0 and 1
|
|
mainEngine.throttleInput = Mathf.Clamp01(target);
|
|
|
|
// Debug the throttle value
|
|
//Debug.Log($"Throttle value: {mainEngine.throttleInput}");
|
|
|
|
// Update the throttle display
|
|
if (throttleDisplay != null)
|
|
{
|
|
throttleDisplay.value = mainEngine.throttleInput;
|
|
}
|
|
}
|
|
}
|