test events during scene execution

1

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?

    
asked by Jakala 09.06.2018 в 10:28
source

1 answer

0

You could use Debug.Log(“nombreEvento”); right where you have the event you want to see if it works. I hope it serves you, and that is what you need. This is just the simplest way to do it.

An example:

public void Accion1(){
//Tu acción 
*Debug.Log(“Nombre de acción “)* 
  } 

In the place of Debug.Log (); you can add some int, in this case the one of life, which would be Debug.Log(“Vida : “ + VidaInt );

    
answered by 03.10.2018 в 20:27