Moved throttle adj to Instrument manager and made altimeter
This commit is contained in:
@@ -1,16 +1,63 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class InstrumentManager : MonoBehaviour
|
||||
{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
[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();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user