© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
3 replies
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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Name does not exist in the current context
C#CC# / help
2y ago
❔ txtDisplay does not exist in the current context
C#CC# / help
3y ago
❔ Name "PostsService" does not exist in the current context
C#CC# / help
4y ago