Files
chameleon/Assets/Scripts/MouseSensitivitySlider.cs
T
adminandClaude Opus 4.8 2a6fc163b1 Add persistent global mouse sensitivity setting with slider
MouseSensitivity is a static, PlayerPrefs-backed multiplier (default 1,
clamped 0.1-4.0) that scales the mouse-look delta in the FreeCam,
FirstPerson and ThirdPerson controllers. Writes flush immediately so the
value survives a hard build exit. MouseSensitivitySlider binds the
Settings-panel slider to it (range read from the inspector) and mirrors
the value into its label, syncing on panel open via OnEnable.

Main.unity now contains the session-manager canvas directly (the
Online Session Manager prefab was unpacked) and wires the slider binder.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-28 13:55:53 +02:00

38 lines
1.1 KiB
C#

using TMPro;
using UnityEngine;
using UnityEngine.UI;
/// Binds a UI Slider (and optional value label) to the global MouseSensitivity
/// multiplier. The slider's range is authored in the inspector (0.1 - 4.0);
/// this only reads/writes the value so scene-side range edits are respected.
public class MouseSensitivitySlider : MonoBehaviour
{
[SerializeField] private Slider slider;
[Tooltip("Optional TMP label showing the current multiplier (e.g. \"1,00\").")]
[SerializeField] private TMP_Text valueLabel;
void OnEnable()
{
if (!slider) return;
slider.SetValueWithoutNotify(MouseSensitivity.Multiplier);
UpdateLabel(MouseSensitivity.Multiplier);
slider.onValueChanged.AddListener(OnSliderChanged);
}
void OnDisable()
{
if (slider) slider.onValueChanged.RemoveListener(OnSliderChanged);
}
void OnSliderChanged(float value)
{
MouseSensitivity.Multiplier = value;
UpdateLabel(value);
}
void UpdateLabel(float value)
{
if (valueLabel) valueLabel.text = value.ToString("0.00");
}
}