Interface method fires multiple times

So i have a slider that that updates on every key press, and it should go up by one whole step, but instead it goes either two,three, and sometimes it goes one step. Please advise me on this one <3

public void onInteract()
{
    float currentTime = Time.time;

    if (peaceStart != 0f)
    {

        peaceEnd = currentTime - peaceStart;
        Debug.Log(peaceEnd);
    }
    peaceStart = currentTime;
    slider.value++;
}

How many times are you calling this function each time a key is pressed? I suspect once you figure that out you will know where to go from here. As it is, there is absolutely nothing we can tell from this single isolated function to determine what the root cause of your problem might be.

1 Like