Esempio n. 1
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.tag == "Player")
     {
         PlayerController health = other.gameObject.GetComponent <PlayerController>();
         health.currentHealth += healthAmount;
         healthBar.TakeDamage(-healthAmount);
         Destroy(gameObject);
         if (health.currentHealth > health.maxHealth)
         {
             health.currentHealth = health.maxHealth;
         }
         Debug.Log("Player gained " + healthAmount + " health");
     }
     if (other.tag == "Player" && isSuperHealth == true)
     {
         PlayerController health = other.gameObject.GetComponent <PlayerController>();
         health.maxHealth    += superHealth;
         health.currentHealth = health.maxHealth;
         healthBar.TakeDamage(-healthAmount);
         healthBar.maximumHealth += superHealth;
         healthBar.GetComponent <HealthBarController>().GetComponent <Slider>().value += superHealth;
         Destroy(gameObject);
         Debug.Log("Maximum Health increased!");
     }
 }
    // Use this for initialization
    void Start()
    {
        if (health == 0)
        {
            health = MAXHEALTH;
        }
        if (MAXHEALTH == 0)
        {
            MAXHEALTH = BASEHEALTH;
        }


        if (GetComponentInParent <MovementControlScript>() != null)
        {
            if (GetComponentInParent <MovementControlScript>().isPlayerShip)
            {
                healthBar    = GameObject.Find("PlayerHealth").GetComponent <HealthBarController>();
                healthSlider = healthBar.GetComponent <Slider>();
            }
        }

        if (GetComponentInParent <TargetObjective>() != null)
        {
            healthBar    = GameObject.Find("BaseHealth").GetComponent <HealthBarController>();
            healthSlider = healthBar.GetComponent <Slider>();
        }

        if (healthSlider != null)
        {
            healthSlider.value = (float)health;
            Debug.Log("Starting Health: " + health);
        }
    }