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
4 replies
❔ while statements
Hello im stuck on a small part of my code im trying to use a while statement but its crashing the game. I dont want multi jumps to go < 0 is there a way to do that with the "multiJump--;"?
if (gI.jumpInput == true)
{
while (multiJump > 0)
{
if (grounded)
{
rb.velocity = new Vector2(gI.valueX * speed, jumpForce);
multiJump--;
}
}
}
gI.jumpInput = false;
multiJump = 1;
35 replies