Guest User

Untitled

a guest
Jan 13th, 2023
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1.  
  2. public class HealthBar : MonoBehaviour
  3. {
  4.     private GameObject healthBar = default;
  5.     private Health currentHealth;
  6.     private float healthBarCoeff;
  7.     void Start()
  8.     {
  9.         healthBar = transform.GetChild(0).gameObject;
  10.         currentHealth = gameObject.GetComponent<Health>();
  11.  
  12.         healthBarCoeff = healthBar.transform.localScale.x / currentHealth.health;
  13.     }
  14.  
  15.     // Можно ли как-то триггернуть функцию ниже только средствами текущего класса, не меняя ничего в классе Health?
  16.     // В самом классе Health есть и переменная health, и методы Damage() и Healing() на которые можно добавить любой функционал
  17.     // Но я хочу узнать, можно ли как-то извне класса либо привязаться к изменению запаса здоровья, либо к вызовам вышеуказанныv методам
  18.     private void UpdateHealthBarSize()
  19.     {
  20.         healthBar.transform.localScale = new Vector3(currentHealth.health * healthBarCoeff, 0.4f, 1);
  21.     }
  22. }
  23.  
Advertisement
Add Comment
Please, Sign In to add comment