Exemplo n.º 1
0
    void OnTriggerEnter2D(Collider2D other)
    {
        // If the player enters the trigger zone...
        if (other.tag == "Player")
        {
            // ... play the pickup sound effect.
            //AudioSource source1 = GameObject.Find("foregrounds").GetComponent<AudioSource>();
            // source1.Play();
            GameObject sounder  = GameObject.Find("foregrounds");
            ExtAudio   extaudio = sounder.GetComponent <ExtAudio>();
            extaudio.sounding.clip = extaudio.bombPickup;
            extaudio.sounding.Play();

            // soundmaker.clip = pickupclip;
            //GetComponent<AudioSource>().clip = pickupClip;

            // Increase the number of bombs the player has.
            other.GetComponent <LayBombs>().bombCount++;
            // Destroy the crate
            Destroy(transform.root.gameObject);
        }
        // Otherwise if the crate lands on the ground...
        else if (other.tag == "ground" && !landed)
        {
            // ... set the animator trigger parameter Land.
            anim.SetTrigger("Land");
            transform.parent = null;
            gameObject.AddComponent <Rigidbody2D>();
            landed = true;
        }
    }
Exemplo n.º 2
0
    public void Explode()
    {
        // The player is now free to lay bombs when he has them.
        layBombs.bombLaid = false;

        // Make the pickup spawner start to deliver a new pickup.
        pickupSpawner.StartCoroutine(pickupSpawner.DeliverPickup());

        // Find all the colliders on the Enemies layer within the bombRadius.
        Collider2D[] enemies = Physics2D.OverlapCircleAll(transform.position, bombRadius, 2 << LayerMask.NameToLayer("Enemies"));

        // For each collider...
        foreach (Collider2D en in enemies)
        {
            // Check if it has a rigidbody (since there is only one per enemy, on the parent).
            Rigidbody2D rb = en.GetComponent <Rigidbody2D>();
            if (rb != null && rb.tag == "Enemy")
            {
                // Find the Enemy script and set the enemy's health to zero.
                rb.gameObject.GetComponent <Enemy>().HP = 0;

                // Find a vector from the bomb to the enemy.
                Vector3 deltaPos = rb.transform.position - transform.position;

                // Apply a force in this direction with a magnitude of bombForce.
                Vector3 force = deltaPos.normalized * bombForce;
                rb.AddForce(force);
            }
        }

        // Set the explosion effect's position to the bomb's position and play the particle system.
        explosionFX.transform.position = transform.position;
        explosionFX.Play();

        // Instantiate the explosion prefab.
        Instantiate(explosion, transform.position, Quaternion.identity);

        // Play the explosion sound effect.
        //AudioSource.PlayClipAtPoint(boom, transform.position);
        GameObject sounder  = GameObject.Find("foregrounds");
        ExtAudio   extaudio = sounder.GetComponent <ExtAudio>();

        extaudio.sounding.clip = extaudio.boom;
        extaudio.sounding.Play();
        // Destroy the bomb.
        Destroy(gameObject);
    }
Exemplo n.º 3
0
    void OnTriggerEnter2D(Collider2D col)
    {
        // If it hits an enemy...
        if (col.tag == "Enemy")
        {
            // ... find the Enemy script and call the Hurt function.
            col.gameObject.GetComponent <Enemy>().Hurt();

            // Call the explosion instantiation.
            OnExplode();

            // Destroy the rocket.
            GameObject sounder  = GameObject.Find("foregrounds");
            ExtAudio   extaudio = sounder.GetComponent <ExtAudio>();
            extaudio.sounding.clip = extaudio.bulletImpact;
            extaudio.sounding.Play();
            Destroy(gameObject);
        }
        // Otherwise if it hits a bomb crate...
        else if (col.tag == "ground")
        {
            OnExplode();
            GameObject sounder  = GameObject.Find("foregrounds");
            ExtAudio   extaudio = sounder.GetComponent <ExtAudio>();
            extaudio.sounding.clip = extaudio.bulletImpact;
            extaudio.sounding.Play();
            Destroy(gameObject);
        }
        else if (col.tag == "BombPickup")
        {
            // ... find the Bomb script and call the Explode function.
            col.gameObject.GetComponent <Bomb>().Explode();

            // Destroy the bomb crate.
            Destroy(col.transform.root.gameObject);

            // Destroy the rocket.
            Destroy(gameObject);
        }
        // Otherwise if the player manages to shoot himself...
        else if (col.gameObject.tag != "Player")
        {
            // Instantiate the explosion and destroy the rocket.
            OnExplode();
            Destroy(gameObject);
        }
    }
Exemplo n.º 4
0
    void OnTriggerEnter2D(Collider2D other)
    {
        // If the player enters the trigger zone...
        if (other.tag == "Player")
        {
            // Get a reference to the player health script.
            PlayerHealth playerHealth = other.GetComponent <PlayerHealth>();

            // Increasse the player's health by the health bonus but clamp it at 100.
            playerHealth.health += healthBonus;
            playerHealth.health  = Mathf.Clamp(playerHealth.health, 0f, 100f);

            // Update the health bar.
            playerHealth.UpdateHealthBar();

            // Trigger a new delivery.
            pickupSpawner.StartCoroutine(pickupSpawner.DeliverPickup());

            // Play the collection sound.
            GameObject sounder  = GameObject.Find("foregrounds");
            ExtAudio   extaudio = sounder.GetComponent <ExtAudio>();
            extaudio.sounding.clip = extaudio.healthPickup;
            extaudio.sounding.Play();
            Destroy(transform.root.gameObject);
        }
        // Otherwise if the crate hits the ground...
        else if (other.tag == "ground" && !landed)
        {
            // ... set the Land animator trigger parameter.
            anim.SetTrigger("Land");

            transform.parent = null;
            gameObject.AddComponent <Rigidbody2D>();
            landed = true;
        }
    }