コード例 #1
0
    public void GotHit(int damage)
    {
        m_healthComponent.ChangeHealth(-damage);
        UpdateHealthColor();

        if (SceneManager.GetActiveScene().name != "TutorialLevel")
        {
            //online
            //socialManager?.UpdateHeavyHitterAchievement();
        }

        if (!m_healthComponent.alive)
        {
            //tell the game manager to give gold
            GameManager.s_instance.GiveGold(20);

            // destroy
            if (SceneManager.GetActiveScene().name != "TutorialLevel")
            {
                LevelManager.s_instance.DestroyEnemy(id);
            }
            else if (SceneManager.GetActiveScene().name == "TutorialLevel")
            {
                TutorialManager.s_instance.ResetEnemy();
                Destroy(gameObject);
            }
        }
    }
コード例 #2
0
    private void AddingResource(GameObject other)
    {
        _audioSourcePickup.pitch = Random.Range(0.8f, 1.2f);
        _audioSourcePickup.Play();

        Debug.Log($"AddingResource");
        var bonus = other.GetComponentInParent <Bonus>();

        switch (bonus.Type)
        {
        case TypeAmmunition.Life:
            GameManager.Instance.LIFE += bonus.Count;
            break;

        case TypeAmmunition.Rocket:
            Ammunitions.CountRockets += bonus.Count;
            break;

        case TypeAmmunition.Health:
            Health.ChangeHealth(+bonus.Count);
            break;

        case TypeAmmunition.Coin:
            GameManager.Instance.ScoreManager.Coins += bonus.Count;
            break;
        }
        Destroy(other);
    }
コード例 #3
0
    private void OnCollisionEnter(Collision other)
    {
        if (other.gameObject.tag == "Enemy")
        {
            Debug.Log("collide enemy");
            if (SceneManager.GetActiveScene().name == "TutorialLevel")
            {
                TutorialManager.s_instance.ResetLevel();
            }
            else
            {
                m_healthComponent.ChangeHealth(-15f);
                AdjustHealthWheelValueAndColor();

                if (SceneManager.GetActiveScene().name != "TutorialLevel")
                {
                    //tell the game manager that the tower took damage
                    if (GameManager.s_instance.towerTookDamage == false)
                    {
                        GameManager.s_instance.towerTookDamage = true;
                        Debug.Log("Took damage");
                    }
                }
            }
        }
        else if (other.gameObject.tag == "EnemyProjectile")
        {
            m_healthComponent.ChangeHealth(-5f);
            AdjustHealthWheelValueAndColor();

            if (SceneManager.GetActiveScene().name != "TutorialLevel")
            {
                //tell the game manager that the tower took damage
                if (tookDamage == false)
                {
                    tookDamage = true;
                    Debug.Log("Took damage");
                }
            }
        }
    }
コード例 #4
0
 public void OnCollisionStay2D(Collision2D hit)
 {
     if (!useTrigger)
     {
         HealthComponent collider = hit.gameObject.GetComponent <HealthComponent>();
         // Only do damage if colliding component has a HealthComponent
         if (collider)
         {
             collider.ChangeHealth((int)(-damageRate * Time.deltaTime));
         }
     }
 }
コード例 #5
0
 public void OnCollisionEnter2D(Collision2D hit)
 {
     if (!useTrigger)
     {
         HealthComponent collider = hit.gameObject.GetComponent <HealthComponent>();
         // Only do damage if colliding component has a HealthComponent
         if (collider)
         {
             collider.ChangeHealth(-enterDamage);
         }
     }
 }
コード例 #6
0
ファイル: ShipBehaviour.cs プロジェクト: EskerGar/Asteroids
        private void OnTriggerEnter2D(Collider2D other)
        {
            var health = other.GetComponent <HealthComponent>();

            if (other.GetComponent <BulletBehaviour>() != null)
            {
                return;
            }
            if (health != null)
            {
                other.GetComponent <HealthComponent>().ChangeHealth(-1);
            }
            _health.ChangeHealth(-1);
        }
コード例 #7
0
 public void TakeDamage(DamageDealerComponent damageDealer)
 {
     _healthComponent.ChangeHealth(damageDealer.Damage);
 }