How do I change the value of a variable with if? c#

Asked 2 years ago, Updated 2 years ago, 127 views

if (Input.GetKeyDown(KeyCode.DownArrow)) {
            int current_health = 10;
            current_health += 30;
            Debug.Log ("Recovery Potion Used" +current_health);
}

The more I press it, the more I want to raise the blood.

10
40
70
100

I want to do it like this, but even if I press it a lot, only 10 + 30 40 keeps coming out.

c# if문 variable

2022-09-22 18:15

1 Answers

int current_health = 10;
if (Input.GetKeyDown(KeyCode.DownArrow)) {
            current_health += 30;
            Debug.Log ("Recovery Potion Used" +current_health);
}

In this way, you can declare the sentence that initializes current_health outside the if statement.


2022-09-22 18:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.