C
C#15mo 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
3 Replies
TheFatMike
TheFatMike15mo ago
figured it out im stupid didnt set up a way public float heal;
Pobiega
Pobiega15mo ago
public void IncreaseHealth(float heal) + public float heal; will cause name collisions.
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.