I have two scripts:
life: assigned to a gameobject Player
StatusController: assigned to a panel where I have two images, one for life and the other for mana
The life script has an event and its delegate, so that when the character's "life" changes (when Damage is executed), launch the ChangeLife event. In addition, the live property is published (to be managed from the editor at runtime and see its values):
public class Life : MonoBehaviour {
[SerializeField] float MaxLive;
public float live;
public delegate void ChangeLive(float value);
public event ChangeLive LiveChange;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
}
public void Damage(float damage) {
live = Mathf.Clamp(live - damage, 0, MaxLive);
var handler = LiveChange;
if (handler != null) {
handler(live);
}
if (live <= 0) {
Deadfx();
}
}
StatusController Connects to the LiveChange event in the start (pick up player with a GameManager):
public class GUIStatusController : MonoBehaviour {
[SerializeField] Image imgLife, imgMana;
GameObject player;
void Start () {
player = GameManager.instance.player;
player.GetComponent<Life>().LiveChange += ChangeLife;
}
void ChangeLife(float value)
{
imgLife.fillAmount = value;
}
The problem I have is that when I run the game, the Life image is not updated. So to test it, when I'm running the editor, I change the value of the property. BUT (and here's the thing) I do not see changes anywhere. I have thought that (perhaps) from the editor at run time, changing values of a property does NOT throw events. If this is the case, I can not test this part of the game.
Is there any way to launch events at run time from the editor, to see if this property (and what I want to do) changes?