Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        float currentHP     = unit.GetCurrentHP();
        float maxHP         = unit.GetMaxHP();
        float HPPercentage  = currentHP / maxHP;
        int   TextureNumber = LayerHealthBarGUIDataArray.Length;
        float divisor       = 1f / (float)TextureNumber;
        int   currentForegroundTextureIndex = HPPercentage == 1 ? TextureNumber - 1 : (int)(HPPercentage * 100) / (int)(divisor * 100);

        topLayeredHealthbar = LayerHealthBarGUIDataArray[currentForegroundTextureIndex];
        if (currentForegroundTextureIndex != 0)
        {
            bottomLayedHealthbar = LayerHealthBarGUIDataArray[currentForegroundTextureIndex - 1];
        }
        else
        {
            bottomLayedHealthbar = null;
        }
        float divisorHP = divisor * maxHP;

        topLayeredHealthbar.realtimeHealthPercentage = (currentHP % divisorHP == 0) ? 1 : (currentHP % divisorHP) / divisorHP;

        topLayeredHealthbar.realtimeColor = Color.Lerp(LayerHealthBarGUIDataArray[currentForegroundTextureIndex].ZeroHealthColor,
                                                       LayerHealthBarGUIDataArray[currentForegroundTextureIndex].FullHealthColor,
                                                       topLayeredHealthbar.realtimeHealthPercentage);

        LocationRect                = HealthBarLocation.GetBound();
        RectOfHealthRealtime        = new Rect(LocationRect);
        RectOfHealthRealtime.width *= topLayeredHealthbar.realtimeHealthPercentage;
        foreach (AdaptiveIcon adaptiveIcon in adaptiveIcons)
        {
            adaptiveIcon.realtimeRect = adaptiveIcon.adaptiveRect.GetBound();
        }
    }
Ejemplo n.º 2
0
 void Awake()
 {
     unit = transform.root.GetComponentInChildren<UnitBase>();
     theMaxValue = unit.GetMaxHP();
 }
Ejemplo n.º 3
0
 void Awake()
 {
     unit        = transform.root.GetComponentInChildren <UnitBase>();
     theMaxValue = unit.GetMaxHP();
 }