Projet-IA-Madelaine/Scripts/MainMenuUI/ScrollerBehavior.cs
2024-06-12 21:03:42 +02:00

44 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class ScrollerBehavior : MonoBehaviour
{
[SerializeField] TMP_Text sliderValue = null;
[SerializeField] Slider slider = null;
[SerializeField] Slider intricatedSlider = null;
[SerializeField] bool canBeSuperiorToIntricated = false;
[SerializeField] bool canBeInferiorToIntricated = false;
float intricatedValue = 0.0f;
void Start()
{
OnIntricatedValueChanged();
OnValueChanged();
}
public void OnValueChanged()
{
float value = slider.value;
if(intricatedSlider != null)
{
if ((!canBeSuperiorToIntricated && value >= intricatedValue) || (!canBeInferiorToIntricated && value <= intricatedValue))
{
slider.value = intricatedValue;
}
}
sliderValue.text = slider.value.ToString("0.0");
}
// Call this method when an intricated slider change its value
public void OnIntricatedValueChanged()
{
if(intricatedSlider != null)
intricatedValue = intricatedSlider.value;
}
}