UI Slider seting max value is delayed
So i have 2 scripts, 1 is the HPBars using Slider this script:
public class HPBars : MonoBehaviour {
public Slider SliderHP;
public void SetMaxHPBar(float HP)
{
SliderHP.maxValue = HP;
SliderHP.value = HP;
}
public void SetCurrentHPBar(float CurrentHP)
{
SliderHP.value = CurrentHP;
}
}
The other one is the Character:
public class CaracterStateMachine: MonoBehaviour {
public GameObject UIRedTeam;
public Caracters NPC;
public HPBars EnemyHPBars;
void Start()
{
NPC = GetComponent<Caracters>();
Instantiate(UIRedTeam, transform.position = this.gameObject.transform.position, transform.rotation);
EnemyHPBars = UIRedTeam.GetComponent<HPBars>();
EnemyHPBars.SetMaxHPBar(NPC.Hp);
}
Well, Everything is working, but for some reason, the max value of my HPbar is delayed.
The value of NPC.Hp is this calculation in another script: "Npc.Hp = BaseHp + Random (0.10)" It works like that. Using random causes this value to vary whenever I press play. What is happening is, I press play NPC.Hp = "example" 45 and the max value of the slider = 0, so I left play and press again Now NPC.Hp = "example" 50 and the max value of the slider = 45 the previous value NPC.Hp And so it goes on, always putting the previous value of the play that I'm
Your answer
Follow this Question
Related Questions
Change Value Of UI Light Slider to Read At Specific Points Of Slider Value 1 Answer
How do I apply a mask to a slider fill so it uses my quadrilateral design 0 Answers
Detect if onValueChanged() of slider is done manually or via script 0 Answers
"Clipping", "Jumping" UI slider, attached to the 2d game object ( health bar) 0 Answers
Stop the camera from rotating when dragging a GUI.slider 2 Answers