コード例 #1
0
    void OnTriggerEnter2D(Collider2D other)
    {
        // If the projectile collides with another GameObject tagged "Enemy" -> take the damageAmount from the enemies health
        if (other.tag == "Enemy")
        {
            // Deal damage to the enemy
            other.GetComponent <EnemyHealthManager> ().TakeDamage(damageAmount);
            // Add score
            gm.AddScore(scoreMultiplier);
            // Instantiate particle effect
            GameObject particle = Instantiate(particleEffect, transform.position, Quaternion.identity) as GameObject;

            // Call the CamMiniShake method
            shake.CamMiniShake();

            // Destroy the particle effect after 1 second
            Destroy(particle, 1f);
            // Destroy the gameObject
            Destroy(gameObject);
        }
        // If the projectile collides with another GameObject tagged "Wall" -> Destroy the projectile
        if (other.tag == "Wall")
        {
            // Instantiate particle effect
            GameObject particle = Instantiate(particleEffect, transform.position, Quaternion.identity) as GameObject;

            // Call the CamMiniShake method
            shake.CamMiniShake();

            // Destroy the particle effect after 1 second
            Destroy(particle, 1f);
            // Destroy the gameObject
            Destroy(gameObject);
        }

        if (other.tag == "TrunkBoss")
        {
            // Deal damage to the enemy
            other.GetComponent <TrunkBossHealthController> ().TakeDamage(damageAmount);
            // Add score
            gm.AddScore(scoreMultiplier);
            // Instantiate particle effect
            GameObject particle = Instantiate(particleEffect, transform.position, Quaternion.identity) as GameObject;

            // Call the CamMiniShake method
            shake.CamMiniShake();

            // Destroy the particle effect after 1 second
            Destroy(particle, 1f);
            // Destroy the gameObject
            Destroy(gameObject);
        }

        if (other.tag == "SlimeBoss")
        {
            // Deal Damage to the boss
            other.GetComponent <SlimeBossHealthController>().TakeDamage(damageAmount);
            // Add Score
            gm.AddScore(scoreMultiplier);
            // Instantaite particle effect
            GameObject particle = Instantiate(particleEffect, transform.position, Quaternion.identity) as GameObject;
            // Call the screenshake method
            shake.CamMiniShake();
            // Destroy particle effect
            Destroy(particle, 1f);
            // Destroy the gameObject
            Destroy(gameObject);
        }
    }