Hello,
I’m trying the create a menu with that uses the scrollbar. I set the scrollbar to a number of steps, when the step changes something happens > if (scrollbar.step = 1) {something}. But how can i detect or check the current step number ?
Greet, Anne
You will have to calculate it yourself. Scrollbar has no min or max value, so scrollbar.Value Range is 0.0f → 1.0f.
To get the position you would have to do something like:
Untested
Scrollbar scrollBar = GetComponent<Scrollbar>();
// initialize the scrollbar
int steps = 5;
scrollBar.numberOfSteps = steps;
scrollBar.onValueChanged.AddListener((value) =>
{
// round to int to catch floating point problems.
int currentStep = Mathf.RoundToInt(value / (1f / (float) bar.numberOfSteps));
});
1 Like
TheFudge:
You will have to calculate it yourself. Scrollbar has no min or max value, so scrollbar.Value Range is 0.0f → 1.0f.
To get the position you would have to do something like:
Untested
Scrollbar scrollBar = GetComponent<Scrollbar>();
// initialize the scrollbar
int steps = 5;
scrollBar.numberOfSteps = steps;
scrollBar.onValueChanged.AddListener((value) =>
{
// round to int to catch floating point problems.
int currentStep = Mathf.RoundToInt(value / (1f / (float) bar.numberOfSteps));
});
there is an update to this code. it stops working after the half.
int currentStep = Mathf.RoundToInt(value / (1f / (float)bar.numberOfSteps));
if (value > 0.5) currentStep -= 1;
1 Like