problem with slider

my slide keeps increasing even after reaching its value
is there a way to stop it after reaching its value?

    public int index;
    public Slider slide;
    public float[] valor;
   
    public void next()//BUTTON CLICK
    {
        Index++;
        if (Index <= 0)
        {
            Index = 0;
        }

        if (Index >= 3)
        {
            Index = 3;
        }
       
        if(Index == 0)
        {
            slide.value = valor[0];
        }

        if(Index == 1)
        {
            slide.value += valor[1];
        }

        if(Index == 2)
        {
            slide.value += valor[2];
        }

        if(Index == 3)
        {
            slide.value += valor[3];
            //float valores = valor[3];
            //slide.maxValue = valores;
        }
    }

We are going to need the rest of your code, it is unclear what your variables are used for. What is this IndexEngine variable? It seems that your index value does never reach a maximum that would reset it.

As mentioned, your code doesn’t make sense. Why do you use Index in all your if statements except the last which uses IndexEngine? Are you sure you didn’t mean Index? And if that isn’t the case, then it increases probably because IndexEngine == 3 and never changes.

I fixed the error at the time of posting, now it’s right

it was an error at the time of posting
take a look Now it’s right

Cool, but you fixed the error, right? So it’s good now?

the posting error has been fixed, but it still persists if i keep clicking even after my index reaches 3, my slider keeps increasing

I’m confused at what you expect to happen. You are resetting index to 3 even when it goes above 3, so every click will still execute the index == 3 code. So slide.value will increase. If you don’t want it to increase the slide.value, then you need to check it’s value before adding to it. Otherwise, don’t keep resetting index back to 3.

the above check does not exceed its index, it is between 0 and 3 even if i wanted he wouldn’t let I will show you a video

here the video with the problem

https://www.youtube.com/watch?v=7MwrOzU-oos

would there be any way to obtain the value that is within your index 3, do not increase more? because if I keep pressing the button the slider keeps increasing?

idk if you are confused or what, but the code is doing exactly what you tell it to.

When you hit index 3, it is always at index 3 after that, why? Because you tell it to.

if (Index >= 3)
{
     Index = 3;
}

Because of that code, your if check for Index value always runs

if(Index == 3)
{
     slide.value += valor[3];
     //float valores = valor[3];
     //slide.maxValue = valores;
}

This code always runs and it always says to take the slide.value and ADD valor[3] to it and THEN set the slide.value equal to that new number.

So if slide.value is 1 and valor[3] is 2 then after that code runs, slide.value is 3. Then when it runs again, slide.value is 5. It is adding valor[3] every single time this if statement runs. So the code is working exactly how you tell it to. If you don’t want it to add the value, you either need to set slide.value = valor[3] or you need to let index move beyond 3 so this if statement doesn’t run after Index changes.

that’s right, I will always call your indexes and successively the value that is within them.

I would like to obtain the value [3] of the slider only once within its respective index
slide.value + = value [3];

Let’s start of by cleaning up this mess, it’s way too confusing. Then we’ll be able to think about the problem.

public class Yolo
{
    // This probably has no reason to be public
    int index = 0;

    // This probably shouldn't be public either but i'll do for now
    public float[] values; // and let's name it correctly
    public Slider slide; // Your class is name slider and your variable slide... it's confusing at best
   
    // C# convention uses Upper case for mtehdos
    public void Next()
    {
        // Is it normal by the way that your variables here had an uppercase but not in the properties?
        index++;

        // Do we have reasons to believe that the index could be lower than zero without public access?
        // if (Index <= 0)
        // {
        //     Index = 0;
        // }
   
        if (index >= values.Length)
        {
            index = 0;   
        }

        // Probably shoudl add some guard here if we have to reasons to believe that the array could be empty
        slide.value = values[index];
    }
}

That may not fix it. Does OP want to set the value or add the value? And does OP want to add it only once or set it only once? The request is a bit unclear.

OP, I would suggest if you want Next to stop, then before index++, check the value and if it’s >= values.Length, you just return. @Magnesium has a lot of good suggestions on how to clean up your code, you just need to clarify if you want to add, set equal to, loop, whatever.