Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class HealthBar : MonoBehaviour
- {
- private GameObject healthBar = default;
- private Health currentHealth;
- private float healthBarCoeff;
- void Start()
- {
- healthBar = transform.GetChild(0).gameObject;
- currentHealth = gameObject.GetComponent<Health>();
- healthBarCoeff = healthBar.transform.localScale.x / currentHealth.health;
- }
- // Можно ли как-то триггернуть функцию ниже только средствами текущего класса, не меняя ничего в классе Health?
- // В самом классе Health есть и переменная health, и методы Damage() и Healing() на которые можно добавить любой функционал
- // Но я хочу узнать, можно ли как-то извне класса либо привязаться к изменению запаса здоровья, либо к вызовам вышеуказанныv методам
- private void UpdateHealthBarSize()
- {
- healthBar.transform.localScale = new Vector3(currentHealth.health * healthBarCoeff, 0.4f, 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment