Beispiel #1
0
    /// <summary>
    /// Take damage and check whether for death.
    /// </summary>
    /// Authors: Courtney Chu, Steven Johnson, Cole Twitchell
    /// <param name="damage">Damage to take.</param>
    public void TakeDamage(float damage, ColorType damageType)
    {
        if (damageType == ColorType.BLACK || damageType == color)
        {
            health -= damage * 2.0f;
        }
        else
        {
            health -= damage;
        }

        if (health <= 0 && !dead)
        {
            dead = true;

            // Setup bloodFly
            Vector3       enemyScreenPos = Camera.main.WorldToViewportPoint(transform.position);
            BloodFly      newBloodFly    = Instantiate(bloodFly, GameManager.canvas.transform);
            RectTransform bloodFlyRect   = newBloodFly.GetComponent <RectTransform>();
            bloodFlyRect.anchorMin        = enemyScreenPos;
            bloodFlyRect.anchorMax        = enemyScreenPos;
            bloodFlyRect.anchoredPosition = new Vector2(0, 0);

            GameManager.AddMoney(value);
            this.SetSpeed(0f);
            EnemyManager.RemoveEnemy(this);
        }
    }
Beispiel #2
0
 /// <summary>
 /// Enables rewards panel so blood can fly to the panel from the enemy.
 ///
 /// Authors: David Askari, Amy Lewis, Steven Johnson
 /// </summary>
 void OnEnable()
 {
     if (GameManager.rewardsPanelFirstEnable)
     {
         GameManager.rewardsPanelFirstEnable = false;
     }
     else
     {
         Vector3       panelScreenPos = Camera.main.WorldToViewportPoint(transform.position);
         BloodFly      newBloodFly    = Instantiate(bloodFly, this.transform);
         RectTransform bloodFlyRect   = newBloodFly.GetComponent <RectTransform>();
         bloodFlyRect.anchorMin        = Vector3.zero;
         bloodFlyRect.anchorMax        = Vector3.zero;
         bloodFlyRect.anchoredPosition = new Vector2(0, 0);
     }
 }