C#C
C#3y ago
TheFatMike

❔ ✅ Does not exist in the current context

Hello i have a class called player stats with

public void IncreaseHealth(float heal)
{
health += heal;

if (health > maxHealth)
health = maxHealth;


UpdateHealth();
}

then i have a another class trying to get that function with the code

private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
PlayerStats playerStats = collision.GetComponentInChildren<PlayerStats>();

if (playerStats.health == playerStats.maxHealth)
return;

playerStats.IncreaseHealth(heal);

GetComponent<SpriteRenderer>().enabled = false;
GetComponent<PolygonCollider2D>().enabled = false;
GetComponent<AudioSource>().Play();

}
}

it all works except the

playerStats.IncreaseHealth(heal);

the heal bit is not in context not sure why
Was this page helpful?