Beispiel #1
0
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Enemy")
        {
            // Try and find an EnemyHealth script on the gameobject hit.
            EnemyHealth enemyHealth = other.GetComponent <EnemyHealth>();

            // If the EnemyHealth component exist...
            if (enemyHealth != null)
            {
                // ... the enemy should take damage.
                enemyHealth.TakeDamage(this);
            }
        }
        else if (other.tag == "BossLegs")
        {
            // Try and find an EnemyHealth script on the gameobject hit.
            BossHealth bossHealth = GameObject.FindGameObjectWithTag("Boss").GetComponent <BossHealth>();

            // If the EnemyHealth component exist...
            if (bossHealth != null)
            {
                // ... the enemy should take damage.
                bossHealth.TakeDamage(this);
            }
        }
        else if (other.tag == "Explosive" && !other.isTrigger)
        {
            ExplosiveBarrel barrel = other.GetComponent <ExplosiveBarrel>();
            barrel.Explode();
        }
        else if (other.tag == "Barrelwall")
        {
            PassWallTrigger passWall = other.GetComponentInParent <PassWallTrigger>();
            passWall.PassOnEffect();
        }
        else if (other.tag == "Firewall" && typeOfBullet == BulletType.Ice)
        {
            ZoneWall zoneWall = other.GetComponent <ZoneWall>();
            zoneWall.DesactivateWall();
        }
        else if (other.tag == "Plantwall" && typeOfBullet == BulletType.Fire)
        {
            ZoneWall zoneWall = other.GetComponent <ZoneWall>();
            zoneWall.DesactivateWall();
        }
        else
        {
            // for other objects
        }

        //print(other.tag);
        if (other.tag == "Player" || other.tag == "FloatingCrystal" || other.tag == "TriggerEffect" || other.tag == "Sight")
        {
            // don't destroy it when it's the player shooting (or the bullet will never go out of the player collider...)
        }
        else if (other.tag == "Well" && other.isTrigger)
        {
            // don't destroy if it impacts the trigger collider of a well
        }
        else if (other.tag == "Explosive" && other.isTrigger)
        {
            // don't destroy if it impacts the trigger collider of an explosive barrel
        }
        else if (other.tag == "Climat")
        {
            // Don't destroy the bullet if it's in a climat's box collider
        }
        else if ((other.tag == "IceWall" || other.tag == "Firewall" || other.tag == "Plantwall") && other.isTrigger)
        {
            // don't destroy if it impacts the trigger collider a destroyed wall
        }
        else
        {
            // in all other case destroy it
            GameObject impactAnim = (GameObject)Instantiate(bulletImpact, this.transform.position, Quaternion.identity);
            // destroy the anim after 1 sec
            Destroy(impactAnim, 1.2f);

            Destroy(this.gameObject);
        }
    }