The question is answered, right answer was accepted
Need help with c#
How to make this shorter.I m a beginner so i dont know much yet but i think i might an array but i dont know how to set it up. Here is the code
void HpUpgradelvl()
{
if (PlayerControl.coins >= 30)
{
healthPoints = healthPoints + 10;
PlayerPrefs.SetFloat("HealthUP", healthPoints);
if (PlayerControl.coins >= 60)
{
txt.SetActive(false);
txt1.SetActive(true);
txt2_0.SetActive(false);
txt2_1.SetActive(true);
healthPoints = healthPoints + 10;
PlayerPrefs.SetFloat("HealthUP", healthPoints);
if (PlayerControl.coins >= 100)
{
txt1.SetActive(false);
txt2.SetActive(true);
txt2_1.SetActive(false);
txt2_2.SetActive(true);
healthPoints = healthPoints + 10;
PlayerPrefs.SetFloat("HealthUP", healthPoints);
if (PlayerControl.coins >= 150)
{
txt2.SetActive(false);
txt3.SetActive(true);
txt2_2.SetActive(false);
txt2_3.SetActive(true);
healthPoints = healthPoints + 10;
PlayerPrefs.SetFloat("HealthUP", healthPoints);
if (PlayerControl.coins >= 210)
{
txt3.SetActive(false);
txt4.SetActive(true);
txt2_3.SetActive(false);
txt2_4.SetActive(true);
healthPoints = healthPoints + 10;
PlayerPrefs.SetFloat("HealthUP", healthPoints);
if (PlayerControl.coins >= 280)
{
txt4.SetActive(false);
txt5.SetActive(true);
txt2_4.SetActive(false);
txt2_5.SetActive(true);
healthPoints = healthPoints + 10;
PlayerPrefs.SetFloat("HealthUP", healthPoints);
if (PlayerControl.coins >= 360)
{
txt5.SetActive(false);
txt6.SetActive(true);
txt2_5.SetActive(false);
txt2_6.SetActive(true);
healthPoints = healthPoints + 10;
PlayerPrefs.SetFloat("HealthUP", healthPoints);
if (PlayerControl.coins >= 450)
{
txt6.SetActive(false);
txt7.SetActive(true);
txt2_6.SetActive(false);
txt2_7.SetActive(true);
healthPoints = healthPoints + 10;
PlayerPrefs.SetFloat("HealthUP", healthPoints);
if (PlayerControl.coins >= 500)
{
txt7.SetActive(false);
txt8.SetActive(true);
txt2_7.SetActive(false);
txt2_8.SetActive(true);
healthPoints = healthPoints + 10;
PlayerPrefs.SetFloat("HealthUP", healthPoints);
if (PlayerControl.coins >= 610)
{
txt8.SetActive(false);
txt9.SetActive(true);
txt2_8.SetActive(false);
txt2_9.SetActive(true);
healthPoints = healthPoints + 10;
PlayerPrefs.SetFloat("HealthUP", healthPoints);
if (PlayerControl.coins >= 730)
{
txt9.SetActive(false);
txt10.SetActive(true);
txt2_9.SetActive(false);
txt2_10.SetActive(true);
healthPoints = healthPoints + 10;
PlayerPrefs.SetFloat("HealthUP", healthPoints);
if (PlayerControl.coins >= 860)
{
txt10.SetActive(false);
txt11.SetActive(true);
txt2_10.SetActive(false);
txt2_11.SetActive(true);
healthPoints = healthPoints + 10;
PlayerPrefs.SetFloat("HealthUP", healthPoints);
if (PlayerControl.coins >= 1000)
{
txt11.SetActive(false);
txtmax.SetActive(true);
imgmax.SetActive(false);
txt2_11.SetActive(false);
txtmax2.SetActive(true);
imgmax2.SetActive(false);
healthPoints = healthPoints + 10;
PlayerPrefs.SetFloat("HealthUP", healthPoints);
}
}
}
}
}
}
}
}
}
}
}
}
}
else healthPoints = 100;
}
This isn't the most reader-friendly piece of code. Could you explain what it's supposed to do?
when you get certain amount coins it increses the health by 10 and it changes the text that displays how much coins you need for next upgrade
Answer by hexagonius · Dec 15, 2015 at 07:23 PM
I think you'd get the help you need on like stackoverflow. This is more a Unity specific Answers site.
Follow this Question
Related Questions
Basic Code Problem 1 Answer
transform.localscale to specific size 1 Answer
Tempreture drop script "spirit ontriggerstay" problems. 0 Answers
Hiding part of mesh 0 Answers
Game working in pc but not in Android While Testing 0 Answers