- Home /
Question by
xproject2013 · Aug 13, 2013 at 01:09 PM ·
guislider
How can i detect changes on a GUI slider?
Hi, i have two sliders and i need that only when the user is moving them a functions is calling. I need to check when a specific slider is changing (for example with a bool like sliderOneisChanging set to true during the movement) and call a function during the value modification, here's the code of the slider:
void OnGUI () {
GUI.contentColor = Color.black;
float width = GUILayout.HorizontalSlider(myVarWidth, 100f, 600f);
float height = GUILayout.HorizontalSlider(myVarHeight, 100f, 600f);
}
Thank in advance for help
Comment
Answer by robertbu · Aug 13, 2013 at 01:58 PM
You can do it this way:
void OnGUI () {
GUI.contentColor = Color.black;
float width = GUILayout.HorizontalSlider(myVarWidth, 100f, 600f);
if (width != myVarWidth) {
// Set a bool or call a funciton
myVarWidth = width;
}
float height = GUILayout.HorizontalSlider(myVarHeight, 100f, 600f);
if (height != myVarHeight {
// Set bool or call a function
myVarHeight = height;
}
}