using UnityEngine; using UnityEngine.UI; [ExecuteAlways] public class SliderHandleController : MonoBehaviour { public Slider slider; public RectTransform sliderRect; // 슬라이더 전체 UI public RectTransform handle; // 핸들 RectTransform public float offsetX = 0f; // X축 오프셋 (필요하면 조정 가능) void Start() { UpdateHandlePosition(); } void Update() { UpdateHandlePosition(); } void UpdateHandlePosition() { // 슬라이더의 좌측(X Min)과 우측(X Max) 계산 float sliderMinX = sliderRect.rect.xMin; float sliderMaxX = sliderRect.rect.xMax; // 현재 슬라이더 값에 대한 핸들의 X 좌표 계산 float handleX = Mathf.Lerp(sliderMinX, sliderMaxX, (slider.value - slider.minValue) / (slider.maxValue - slider.minValue)); // 핸들 위치 업데이트 handle.anchoredPosition = new Vector2(handleX + offsetX, handle.anchoredPosition.y); } }