Search Unity

how do I update health value and slider from item buff value when equipped to equipment inventory.

Discussion in '2D' started by kdawgfsho04, Nov 18, 2020.

  1. kdawgfsho04

    kdawgfsho04

    Joined:
    Aug 3, 2020
    Posts:
    18
    Trying to figure out how to update my health and health slider when an item with a buff value is equiped to a slot..
    here is the code for when the item and buff are added to equipment inventory.
    i tried putting slider.value = playerHealth.playercurrentHealth; above print message but i think i need another value?? im not sure.. and help would be super appreciated.. i also have to remove it from health and slide when removed.. i add a screen shot of the code.
     

    Attached Files:

  2. rubcc95

    rubcc95

    Joined:
    Dec 27, 2019
    Posts:
    222
    Yout talk about sliders and playerHealths, but we can't see how you implement it. That message is far away from conventions, next time try to paste your code instead of a png file, in order to be able to copy it. This is some idea which may be useless since we've not the appropiate info.
    Code (CSharp):
    1. void OnBuffAdded(Buff buff)
    2. {
    3.      slider.maxValue += buff.value;
    4.      slider.value += buff.value;
    5. }
    6.  
    7. void OnBuffRemoved(Buff buff)
    8. {
    9.     slider.maxValue -= buff.value;
    10.     if(slider.value > slider.maxValue) slider.value = slider.maxValue;
    11. }
    Code (CSharp):
    1. [code=CSharp]void OnBuffAdded(Buff buff)
    2. {
    3.      slider.maxValue += buff.value;
    4.      slider.value += buff.value;
    5. }
    6.  
    7. void OnBuffRemoved(Buff buff)
    8. {
    9.     slider.maxValue -= buff.value;
    10.     if(slider.value > slider.maxValue) slider.value = slider.maxValue;
    11. }
    [/code]