- Home /
Using Gui button to alter Slider Value
As usualy i might be overthinking this completely but here goes..
i've made a slider, non-interactable as i don't want the players of the game to alter the value of the slider. Next to the slider i've made a gui button ( i'm using the "new gui" of unity for all of this btw. ) The idea is that when a player clicks the button ( not the slider ) the value of the slider will increase the value of 1. My issue is that with the script i'm using nothing really happens despite the fact that i get no errors.
basicly what i'm after here is a more simple solution on how to make the button increase the slider value by 1. I'm fairly green on this new UI system and would really like to get to use it more as it seems quite interresting. Basicly i'm hoping theres a way to do this with just the in-built gui features but all i've gotten so far with those is that i can increase the value to a set amount rather than add points.
Anyone out there with a better understanding of this UI that could give me a pointer on how to make this happen?
Answer by Umresh · Jul 14, 2015 at 01:22 PM
Get the slider component and from that get the value property in a public function of a script attach it to a Gameobject and add it to button listener and add that function.
public void sliderIncrease()
{
Slider _slider = gameobject.GetComponent<Slider>();
_slider.value = slider.value + 1;
}
So basicly i'm scripting my way out of it anyway? :p fair enough, it was as i expected then, had just hoped there'd be a more in-built solution :) thanks for the answer anyway
Ended up using a different script but works just as well i suppose:
#pragma strict
public var slider1 : UnityEngine.UI.Slider;
function Start () {
}
function Update () {
if (Input.Get$$anonymous$$ouseButtonDown(0))
slider1.value = slider1.value +1;
}