가운데 부터 시작해서 양쪽을 채우는 슬라이더
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(Slider))]
public class SliderSwitcher : MonoBehaviour
{
private Slider _slider;
void Awake()
{
_slider = GetComponent<Slider>();
_slider.onValueChanged.AddListener(delegate { UpdateSliderSense(); });
}
private void Start()
{
UpdateSliderSense(); // init
}
public void UpdateSliderSense()
{
if (_slider.value > 0)
{
_slider.fillRect.anchorMin = new Vector2(0.5f, 0);
_slider.fillRect.anchorMax = new Vector2(_slider.handleRect.anchorMin.x, 1);
}
else
{
_slider.fillRect.anchorMin = new Vector2(_slider.handleRect.anchorMin.x, 0);
_slider.fillRect.anchorMax = new Vector2(0.5f, 1);
}
}
}
댓글 없음:
댓글 쓰기