Hey Guys,
I’m kinda new to Unity with C# and I wrote a Script for the Healthbar.
My Script looks untidy. Could anyone help me clean this mess up or someone who can explain to do that in a better way?
//TopScreen GUI - Hearts
public GameObject full_3;
Animator full_3_anim;
public GameObject full_2;
Animator full_2_anim;
public GameObject full_1;
Animator full_1_anim;
public GameObject half_3;
Animator half_3_anim;
public GameObject half_2;
Animator half_2_anim;
public GameObject half_1;
Animator half_1_anim;
public GameObject empty_3;
public GameObject empty_2;
public GameObject empty_1;
public GameObject Player;
public GameObject BottomCam;
public GameObject GameoverCam;
void Awake()
{
full_3_anim = full_3.GetComponent<Animator> ();
full_2_anim = full_2.GetComponent<Animator> ();
full_1_anim = full_1.GetComponent<Animator> ();
half_3_anim = half_3.GetComponent<Animator> ();
half_2_anim = half_2.GetComponent<Animator> ();
half_1_anim = half_1.GetComponent<Animator> ();
full_3_anim.speed = 0.33f;
full_3_anim.Play("Beat");
}
//----------------------------------------------------------------
IEnumerator GetDamage() {
Debug.Log ("Damage Got");
if(Life == 1){
Life = Life-1;
half_1.SetActive(false);
empty_1.SetActive(true);
Player.SetActive(false);
BottomCam.SetActive(false);
GameoverCam.SetActive(true);
Application.LoadLevelAsync("BootScreen");
} else if(Life == 2){
Life = Life-1;
full_1.SetActive(false);
half_1.SetActive(true);
half_1_anim.speed = 0.66f;
half_1_anim.Play("Beat");
yield return new WaitForSeconds(0);
} else if(Life == 3){
Life = Life-1;
half_2.SetActive(false);
empty_2.SetActive(true);
full_1_anim.speed = 0.48f;
full_1_anim.Play("Beat");
yield return new WaitForSeconds(0);
} else if(Life == 4){
Life = Life-1;
full_2.SetActive(false);
half_2.SetActive(true);
half_2_anim.speed = 0.33f;
half_2_anim.Play("Beat");
yield return new WaitForSeconds(0);
} else if(Life == 5){
Life = Life-1;
full_2_anim.speed = 0.33f;
full_2_anim.Play("Beat");
half_3.SetActive(false);
empty_3.SetActive(true);
yield return new WaitForSeconds(0);
} else if(Life == 6){
Life = Life-1;
full_3.SetActive(false);
half_3.SetActive(true);
half_3_anim.speed = 0.33f;
half_3_anim.Play("Beat");
yield return new WaitForSeconds(0);
}
Debug.Log (Life + " left");
}
