Exemple #1
0
    /// <summary>
    /// Checks if an enemy object has entered it and damages the "Base" object.
    /// Checks if any enemies are remaining after.
    /// </summary>
    /// <param name="other">The object that enters the trigger.</param>
    void OnTriggerEnter(Collider other)
    {
        GameObject obj = other.gameObject;

        if (obj.tag == "Enemy")
        {
            currentHealth -= obj.GetComponent <Enemy>().damage;

            Transform pivot = healthBar.transform.Find("HealthyPivot");
            Vector3   scale = pivot.localScale;
            scale.x = Mathf.Clamp(currentHealth / health, 0, 1);

            pivot.localScale = scale;

            Destroy(obj);
            CheckIfNoEnemy checkEnemy = new CheckIfNoEnemy();
            checkEnemy.NoEnemy();
            CheckHealth();
        }
    }
Exemple #2
0
    /// <summary>
    /// Used when the enemy is hit.
    /// </summary>
    /// <param name="damage">How much damage the enemy takes.</param>
    public void Hurt(float damage)
    {
        healthBar.SetActive(true);
        currentHealth -= damage;

        if (currentHealth <= 0)
        {
            Money.amount += worth;
            Destroy(gameObject);

            CheckIfNoEnemy checkEnemy = new CheckIfNoEnemy();
            checkEnemy.NoEnemy();
        }

        Transform pivot = healthBar.transform.Find("HealthyPivot");
        Vector3   scale = pivot.localScale;

        scale.x = Mathf.Clamp(currentHealth / health, 0, 1);

        pivot.localScale = scale;
    }