Example #1
0
    private void CreateNewUIBar()
    {
        if (objPlayer == null)
        {
            return;
        }
        if (objUIBar != null)
        {
            Destroy(objUIBar);
        }
        objUIBar = Instantiate(prefabUIBar);
        objUIBar.SetActive(false);
        DontDestroyOnLoad(objUIBar);
        UIBar  bar    = objUIBar.GetComponent <UIBar>();
        Player player = objPlayer.GetComponent <Player>();

        player.OnChangedLevel += bar.setLevel;
        player.OnChangedExp   += bar.ExpBar.SetupValue;
        player.OnChangedHP    += bar.HpBar.SetupValue;
        player.OnChangedSP    += bar.SpBar.SetupValue;

        bar.setLevel(player.level);
        bar.HpBar.SetupValue(player.hp, player.hpMax);
        bar.SpBar.SetupValue(player.sp, player.spMax);
        bar.ExpBar.SetupValue(player.exp, player.expRequired);
    }