Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: AxelF on May 20, 2014, 09:34:40 AM
-
Hi,
I'm a happy new NGUI customer and want to say a big "thank you" at first - it saves me a lot of time. However, now that I'm digging deeper into all its features I encountered my first problem: I'm setting the value of an UISlider object in my script and hoped it would update its appearance automatically afterwards (button position e.g.). Well - it's not working and I wonder why. Is it not enough to simply change the variable "value"? What else is needed so the slider updates itself correctly?
Thanks in advance for any help!
Regards, Axel
-
Changing the UISlider's 'value' is enough. What's the full code you're using here?
-
Its a simple call of my my slider object like "slider.value = 1" in the Start() function of another GUI object. I guess the problem is somewhere in my code then. But it's good to know it should work at least.
-
This might help, its how I update a UISlider as a healthbar
using UnityEngine;
using System.Collections;
public class VitalBar : MonoBehaviour {
public UILabel healthBarLabel;
private UISlider vitalSlider;
private float _maxWidth;
private bool _displayText = false;
void Awake (){
vitalSlider = GetComponent<UISlider> ();
if (vitalSlider == null) {
Debug.LogError("Could not find the UISlider Component!");
return;
}
_maxWidth = vitalSlider.foregroundWidget.localSize.x;
_displayText =true;
}
// Use this for initialization
void Start () {
UpdateDisplay (- 5f, "100/200");
}
//vitalSlider.sliderValue = health/healthBarLabel;
public void UpdateDisplay(float x ){
if (x > 0)
x = 0;
else if (x > 1)
x = 1;
vitalSlider.value = 50;
DisplayText = false;
}
public void UpdateDisplay(float x, string str ){
UpdateDisplay (x);
if (str != "") healthBarLabel.text = str;
}
public bool DisplayText {
get { return _displayText;}
set { _displayText = value;
if (!_displayText)
healthBarLabel.text = ""; }
}
}
-
Slider's value goes from 0 to 1. You're passing '50'.
-
Wow, that is strange. If the parent GameObject of the slider (a UISprite) contains a Tween Scale component I can not set the value visually of the slider object. If I deactivate the Tween component it works. I have absolutely no explanation for this behavior. If the parent object is a panel the problem persists, so it's not UISprites fault.
-
TweenScale from which value? If it's zero, then that's an invalid scale (you can't divide by zero).
-
if we use 'public UISlider slideBAR'....then what should be given as reference for this...
I tried this but i couldn't find any 'UISlider' for referencing ..