0

I am using NGUI kit in Unity3D to build a progress bar. UISlider script has the value ranging from 0 to 1 to control the slider.

My script is on the same object and i am using this way to set its value according to time (60sec).

this.gameObject.GetComponent().sliderValue = _______ ;

But it is not getting it done. Kindly help me out.

TalhaDX
  • 1
  • 5

1 Answers1

1

You are not asking for the right type UISlider:

this.gameObject.GetComponent<UISlider>().sliderValue= _______ ;

Btw it is good practice to assume anything you get returned maybe a null (afterall you may not have the component attached), so it would be better to:

UISlider lMySlider= this.gameObject.GetComponent<UISlider>();
if(lMySlider!=null)
{
    lMySlider..sliderValue= _______ ;
}
else
{
    Debug.Log ( this.gameObject.name " is missing the UISlider")
}
Rudolfwm
  • 689
  • 6
  • 15