Hello, I currently have a slider that can be adjusted via the slider itself or one of two NGUI buttons (up and down). When the "up" or "down" button is pressed the value increases or decreases as expected. However, pressing the "up" folowed by the "down" button causes the value to increase by one, then continued presses on the "down" button act as expected.
Example:
Power = 300
Press up button: Power = 301
Press up button: Power = 302
Press down button: Power = 303 << This is the problem
Press down button: Power = 302
Press down button: Power = 301
Here is the code that is on the NGUI Slider:
static var power: int; //power that will be passed to the egg when shot
var slider: UISlider; //will become the <Power_Slider>s <UISlider> component
//values for the slider
var minPower: int = 200; //the min power that the slider will be able to input
var maxPower: int = 500; //the max power that the slider will be able to input
function Start()
{
slider = gameObject.GetComponent(UISlider); //get the <UISlider> component of the power slider
}
function Update ()
{
power = Mathf.Lerp(minPower,maxPower,slider.sliderValue); //set the sliders min and max values
}
And here is the code on the NGUI Buttons:
var powerSlider: UISlider; //to get and adjust the slider value
private var sliderInc: float = 0.003335;
function OnMouseUpAsButton()
{
if(gameObject.name == "Power_Button_Up") //if the <Up_Button> is pressed then increase the slider value...
{
powerSlider.sliderValue = powerSlider.sliderValue + sliderInc;
print(gameObject.name + "s power is: " + GameObject.Find("Power_Slider").GetComponent(PowerSlider).power);
}else //else the down button was pressed so decrease the slider value...
{
powerSlider.sliderValue = powerSlider.sliderValue - sliderInc;
print(gameObject.name + "s power is: " + GameObject.Find("Power_Slider").GetComponent(PowerSlider).power);
}
}
Any help will be appreciated to lead me in the right direction to fix this issue.
Thanks in advance,