-4
I don’t understand why but the player object is null , I’m not calling it right ?
public class HealthBar : MonoBehaviour {
Vector3 localScale;
public Transform HealthTransform;
public Player PlayerObj;
void Start () {
localScale = HealthTransform.localScale;
PlayerObj = new Player();
}
void Update () {
if(PlayerObj.GetPlayerAxis().Equals("P1Horizontal"))
{
localScale.x = Player.HealthAmountP1;
if (gameObject.name.Equals("P1Health"))
{
HealthTransform.localScale = localScale;
}
}
if (PlayerObj.GetPlayerAxis().Equals("P2Horizontal"))
{
localScale.x = Player.HealthAmountP2;
if(gameObject.name.Equals("P2Health"))
{
HealthTransform.localScale = localScale;
}
}
}
}
If you run Update before Start you will definitely be null.
– Ricardo Pontual
And gameobject, you instance where?
– Leandro Angelo