Using C sharp, how would one go about changing the value of a slider set from 0-0.75 using a UI button. Using increments of 0.1 each time the button is pressed. I have been battling this question for 2 days trying to understand how a button and a slider can interact with each other. So, any ideas are very much appreciated!
Add ButtonClick Event in Button
void OnButtonClicked(){
slider.value += 0.1f;
}
make sure your sliders min value is 0 and max value is 0.75
-
Use UnityEngine.UI Name space
-
Then Create Slider Variable
public Slider ui;
Assign Script to ui button , -
Drag and Drop your Slider object from canvas to that public field inside script (Hoping that you know basic concepts of unity as well)
-
Then Create Button variable like you did for Slider
public Button yourButton;
and Create Click Event. If don’t know then go here https://docs.unity3d.com/ScriptReference/UI.Button-onClick.html -
And instead for Printing something just increment slider.value with desired value . https://docs.unity3d.com/ScriptReference/UI.Slider-value.html