Currently I am creating a Health Bar for my player and am updating the value in another class. The value being returned that is incorrect is the _fillAmount variable who is inheriting from the BarValue property. Using Debug statements I have identified that the _fillAmount value is being updated correctly in the BarValue property but when the Update function calls HandleBar() it is not receiving the updated _fillAmount value, stating it is still the originial value of 1. Below is my code, any suggestions?
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ui_bar : MonoBehaviour {
private float _fillAmount = 1;
private Image _content;
public float MaxValue {
get;
set;
}
public float BarValue {
set {
_fillAmount = H_Calc (value, 0, MaxValue, 0, 1);
Debug.Log ("Updated Fill Amount Value to " + _fillAmount + ".");
}
}
// Update is called once per frame
void Update (){
HandleBar ();
}
private void HandleBar(){
Debug.Log ("Fill Amount Value " + _fillAmount + ".");
if (_fillAmount != _content.fillAmount) {
_content.fillAmount = _fillAmount;
Debug.Log ("Fill is now " + _fillAmount + ".");
}
}
private float H_Calc(float _value, float _inMin, float _inMax, float _outMin, float _outMax){
return (_value - _inMin) * (_outMax - _outMin) / (_inMax - _inMin) + _outMin;
}
}