Esempio n. 1
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        print("hit");
        ProjectileController controller = collision.gameObject.GetComponent <ProjectileController>();

        if (controller != null)
        {
            if (controller.type == ProjectileController.Type.Player)
            {
                // if it hits an enemy projectile, then decrease lives and then destroy the bullet
                GameManager.TotalScore++;
                EnemySoundEffectHandler.edamaged = true;
                controller.Destroy();
                // fire death animation, sound and disable functionality
                animator.SetBool("hit", true);
                GetComponent <Collider2D>().enabled = false;
                StartCoroutine(ExecuteAfterTime(.5f));
            }
        }
        // if powerups collide with enemy, delete powerup
        if (collision.gameObject.tag == "BlockPUP" || collision.gameObject.tag == "BlockPUP" || collision.gameObject.tag == "DeathPUP" || collision.gameObject.tag == "FirePUP" || collision.gameObject.tag == "HealthPUP" || collision.gameObject.tag == "TimePUP")
        {
            Destroy(collision.gameObject);
        }
    }
Esempio n. 2
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        ProjectileController controller = collision.gameObject.GetComponent <ProjectileController>();

        if (controller != null)
        {
            if (controller.type == ProjectileController.Type.Enemy)
            {
                // if it hits an enemy projectile, then decrease lives and then destroy the bullet
                GameManager.TotalLifes--;
                SoundEffectHandler.damaged = true;
                controller.Destroy();
                animator.SetBool("phit", true);
                StartCoroutine(ExecuteAfterTime(1));
            }
        }
        // if you have hit the health powerup
        if (collision.gameObject.tag == "HealthPUP")
        {
            // if you have collided and theres less than 3 lifes
            if (GameManager.TotalLifes < 3)
            {
                // add a life
                GameManager.TotalLifes++;
            }
            // destroy the object afterwsrds regardless
            Destroy(collision.gameObject);
        }
        // if you have hit the firerate powerup
        if (collision.gameObject.tag == "FirePUP")
        {
            // temporarily store fire rate
            float oldFireRate = fireRate;
            // destroy the collided object
            Destroy(collision.gameObject);
            // set the firerate to 4x original speed
            fireRate *= 4.0f;
            // set a temporary delay timer for 5s
            while (timer > 0)
            {
                timer -= Time.deltaTime;
            }
            // set time back
            timer = 5;
            // reset fire rate
            fireRate = oldFireRate;
        }
        if (collision.gameObject.tag == "BlockPUP")
        {
            // destrouy colliding object
            Destroy(collision.gameObject);
            // spawn block
            Instantiate(theBlock, new Vector3(transform.position.x, transform.position.y + 2, transform.position.z), Quaternion.identity);
        }
        if (collision.gameObject.tag == "TimePUP")
        {
            // destroy colliding object
            Destroy(collision.gameObject);
            // set the timers to be beneficial
            GameManager.timeLeft       = 5f;
            WaveController.wavetimer  += 11f;
            WaveController.powertimer -= 11f;
        }
        if (collision.gameObject.tag == "DeathPUP")
        {
            // destroy object
            Destroy(collision.gameObject);
            // decrease lives, decrease wave time and put sound on damage
            GameManager.TotalLifes--;
            SoundEffectHandler.damaged = true;
            WaveController.wavetimer  -= 5f;
            animator.SetBool("phit", true);
            StartCoroutine(ExecuteAfterTime(1));
        }
        if (collision.gameObject.tag == "Enemy")
        {
            // delete enemy
            Destroy(collision.gameObject);
            // remove life
            GameManager.TotalLifes--;
            SoundEffectHandler.damaged = true;
            animator.SetBool("phit", true);
            StartCoroutine(ExecuteAfterTime(1));
        }
    }