Esempio n. 1
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.CompareTag("Player"))
     {
         scoreHandler.AddToScore(scoreToAdd);
         Destroy(gameObject);
     }
 }
 private void OnParticleCollision(GameObject other)
 {
     if (other.GetComponent <PlayerController>())
     {
         return;
     }
     if (health.GetHealth() <= 0)
     {
         Destroy(gameObject);
         GameObject deathVFX = Instantiate(deathExplosion, transform.position, Quaternion.identity) as GameObject;
         deathVFX.transform.parent = parent;
         Destroy(deathVFX, 1.5f);
         scoreHandler.AddToScore(score);
     }
     health.DealDamage(player.GetBulletDamage());
 }
Esempio n. 3
0
    private void checkCollisions(Collision2D collision)
    {
        if (collision.gameObject.tag == "Tank")
        {
            endGameScript.EndTheGame(collision.gameObject);
            return;
        }

        if (collision.gameObject.tag == "Enemy")
        {
            Destroy(collision.gameObject);
            scoreHandlerScript.AddToScore(100);

            GameObject     newParticleObject = Instantiate <GameObject>(enemyParticlesObject);
            ParticleSystem particleSystem    = newParticleObject.GetComponent <ParticleSystem>();
            particleSystem.transform.position = collision.gameObject.transform.position;
            particleSystem.Play();
            AudioSource.PlayClipAtPoint(Resources.Load <AudioClip>("GameScene/Audio/explosion"), new Vector3(0, 0, 0));
            Destroy(newParticleObject, particleSystem.main.startLifetime.constant); // destroy after the lifetime of the particles
            return;
        }
    }
Esempio n. 4
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        ShotScript shot = other.gameObject.GetComponent <ShotScript>();

        if (shot != null)
        {
            // Avoid friendly fire
            if (shot.belongsToEnemy != isEnemy)
            {
                Damage(shot.damage);
                if (!isEnemy)
                {
                    HealthBarScript.SetHealthBarValue(HealthBarScript.GetHealthBarValue() - 0.1f);
                }
                else
                {
                    ScoreHandler.AddToScore(100);
                }

                // Destroy the shot
                Destroy(shot.gameObject); // Remember to always target the game object, otherwise you will just remove the script
            }
        }
    }
Esempio n. 5
0
    public void TakeDamage(int damageAmount, Transform attacker, bool attackerInOverdrive = false)
    {
        if (!isInvulnerable)
        {
            int finalDamageAmount;
            if (attackerInOverdrive)
            {
                finalDamageAmount = damageAmount * 2;
            }
            else
            {
                finalDamageAmount = damageAmount;
            }

            ScoreHandler attackerScore = null;

            //update myAttacker to reflect this agent's current attacker; this will then be available to the Retreat State so this agent can run away from the attacker
            if (attacker.CompareTag("Player") || attacker.CompareTag("Enemy"))
            {
                myAttacker    = attacker;
                attackerScore = attacker.GetComponent <ScoreHandler>();
            }

            if (isUsingShield && shields > 0)
            {
                shields -= finalDamageAmount;
                if (shields <= 0)
                {
                    //DetonateElectricalCharge();
                }
            }
            else
            {
                currentHP -= finalDamageAmount;

                if (attackerScore != null)
                {
                    attackerScore.AddToScore(finalDamageAmount);
                }

                //Debug.Log(gameObject.name + " took " + damageAmount + " damage, now has hp: " + currentHP);
                if (gameObject.CompareTag("Enemy"))
                {
                    ShouldUseShield(true);
                }

                SetMyValueAsATarget();

                if (currentHP <= 0)
                {
                    if (attackerScore != null)
                    {
                        attackerScore.IncreaseKillstreak();
                    }

                    if (!gameObject.CompareTag("Non-playables"))
                    {
                        Die();
                    }
                    else
                    {
                        AOScript.audio.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
                        AOScript.audio.release();
                        Destroy(gameObject);
                    }
                }
            }
        }
        else
        {
            //Debug.Log(gameObject.name + " is INVULNERABLE!!!");
        }
    }