Hello,(I’m French, sorry for my english) my problem is the following one:
I have 4 different sliders that I manage with the mouse (values from 0 to 255) and Int equal to 510 which decrements according to the value of the current sliders. This Int corresponds among points which we can attribute to the player according to 4 statistics.
I would want to know if it is possible to block the movement towards the right of sliders when this Int is equal to 0. They should not be to block towards the left to be able to modify the changes of statistics.
Thank you for helping me.
Something like this ?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class SliderLimitation : MonoBehaviour {
Slider slider;
float currentValue;
void Start () {
slider = GetComponent<Slider>();
slider.onValueChanged.AddListener(ListenerMethod);
currentValue = slider.value;
}
public void ListenerMethod(float value)
{
if (value < currentValue)
slider.value = currentValue;
else
currentValue = value;
}
}
Thank you very much for your answer.
It is not exactly what I wanted but thanks to you I made a success.
I did not know AddListener. Thank you.
This it interests you: here is how I transformed:
Slider slider;
int currentValue;
public Text EV;
int reste;
void Start ()
{
slider = GetComponent<Slider>();
slider.onValueChanged.AddListener(ListenerMethod);
currentValue = (int)slider.value;
}
public void ListenerMethod(float value)
{
reste = int.Parse(EV.text);
if ( ((int)value - currentValue) <= reste )
currentValue = (int)value;
else
slider.value = currentValue;
}