Hi! So I’m trying to make my health bar script more efficient. As of right now it does a GetComponent check every frame, which seems unreasonable. So what I’m wanting to know is can I replace a GetComponent by directly accesesing the scripts traits through a public variable? Right now I have
public GameObject owner;
void Update () {
{
CurrentHealth = (float)owner.GetComponent<PlayerHealth> ().Health;
HealthMax = (float)owner.GetComponent<PlayerHealth> ().MaxHealth;
}
This script works, but could I replace it with
public Health PlayersHealth;
public MaxHealth PlayerMax;
void Update () {
CurrentHealth = (float)PlayersHealth;
HealthMax = (float)PlayerMax;
}
If it’s not doable it will be fine, but if I can do this small amount of pollish it would be very relieving.