Example #1
0
 void handleAutoPlayerSwap()
 {
     if (Tommy.GetComponent <Hero> ().currentHealth <= 0 &&
         Jerry.GetComponent <Hero> ().currentHealth <= 0 &&
         Poilu.GetComponent <Hero> ().currentHealth <= 0 &&
         Doughboy.GetComponent <Hero> ().currentHealth <= 0)
     {
         gameOver();
     }
     else if (currentHero.currentHealth <= 0)
     {
         if (currentHero.name.Equals("Tommy"))
         {
             Tommy.SetActive(false);
             Jerry.SetActive(true);
             Poilu.SetActive(false);
             Doughboy.SetActive(false);
             currentHero = Jerry.GetComponent <Hero> ();
             handleAutoPlayerSwap();
         }
         else if (currentHero.name.Equals("Jerry"))
         {
             Tommy.SetActive(false);
             Jerry.SetActive(false);
             Poilu.SetActive(true);
             Doughboy.SetActive(false);
             currentHero = Poilu.GetComponent <Hero> ();
             handleAutoPlayerSwap();
         }
         else if (currentHero.name.Equals("Poilu"))
         {
             Tommy.SetActive(false);
             Jerry.SetActive(false);
             Poilu.SetActive(false);
             Doughboy.SetActive(true);
             currentHero = Doughboy.GetComponent <Hero> ();
             handleAutoPlayerSwap();
         }
         else if (currentHero.name.Equals("Doughboy"))
         {
             Tommy.SetActive(true);
             Jerry.SetActive(false);
             Poilu.SetActive(false);
             Doughboy.SetActive(false);
             currentHero = Tommy.GetComponent <Hero> ();
             handleAutoPlayerSwap();
         }
     }
     healthBar.value = calculateHealth();
 }
Example #2
0
 void handleManualPlayerSwap()
 {
     if (Input.GetKeyDown(KeyCode.Alpha1) && (!currentHero.name.Equals("Tommy")) && Tommy.GetComponent <Hero>().currentHealth > 0)
     {
         Tommy.SetActive(true);
         Jerry.SetActive(false);
         Poilu.SetActive(false);
         Doughboy.SetActive(false);
         currentHero = Tommy.GetComponent <Hero> ();
     }
     else if (Input.GetKeyDown(KeyCode.Alpha2) && (!currentHero.name.Equals("Jerry")) && Jerry.GetComponent <Hero>().currentHealth > 0)
     {
         Tommy.SetActive(false);
         Jerry.SetActive(true);
         Poilu.SetActive(false);
         Doughboy.SetActive(false);
         currentHero = Jerry.GetComponent <Hero> ();
     }
     else if (Input.GetKeyDown(KeyCode.Alpha3) && (!currentHero.name.Equals("Poilu")) && Poilu.GetComponent <Hero>().currentHealth > 0)
     {
         Tommy.SetActive(false);
         Jerry.SetActive(false);
         Poilu.SetActive(true);
         Doughboy.SetActive(false);
         currentHero = Poilu.GetComponent <Hero> ();
     }
     else if (Input.GetKeyDown(KeyCode.Alpha4) && (!currentHero.name.Equals("Doughboy")) && Doughboy.GetComponent <Hero>().currentHealth > 0)
     {
         Tommy.SetActive(false);
         Jerry.SetActive(false);
         Poilu.SetActive(false);
         Doughboy.SetActive(true);
         currentHero = Doughboy.GetComponent <Hero> ();
     }
     healthBar.value = calculateHealth();
 }