Пример #1
0
    //If bullet hits enemy, or spawner, then they take damage and bullet object is destroyed
    void OnTriggerEnter2D(Collider2D hitInfo)
    {
        //getting hit info
        EnemyAI        enemy      = hitInfo.GetComponent <EnemyAI>();
        ShotgunEnemyAI Shotgunner = hitInfo.GetComponent <ShotgunEnemyAI>();
        EnemySpawner   spawner    = hitInfo.GetComponent <EnemySpawner>();
        EnemyTransport transport  = hitInfo.GetComponent <EnemyTransport>();

        //checking type of enemy, and then damaging accordingly
        if (enemy != null)
        {
            enemy.TakeDamage(damage);
        }
        if (transport != null)
        {
            transport.TakeDamage(damage);
        }
        if (Shotgunner != null)
        {
            Shotgunner.TakeDamage(damage);
        }
        if (spawner != null)
        {
            spawner.TakeDamage(damage);
        }

        //instantiate bullet impact effect
        Instantiate(impactEffect, transform.position, transform.rotation);

        //destroying bullet after contact is made with another game object
        Destroy(gameObject);
    }
Пример #2
0
    void OnTriggerEnter2D(Collider2D hitInfo)
    {
        EnemyAI        enemy      = hitInfo.GetComponent <EnemyAI>();
        ShotgunEnemyAI Shotgunner = hitInfo.GetComponent <ShotgunEnemyAI>();
        EnemySpawner   spawner    = hitInfo.GetComponent <EnemySpawner>();

        if (enemy != null)
        {
            enemy.TakeDamage(damage);
        }
        if (Shotgunner != null)
        {
            Shotgunner.TakeDamage(damage);
        }
        if (spawner != null)
        {
            spawner.TakeDamage(damage);
        }
        Instantiate(impactEffect, transform.position, transform.rotation);

        Destroy(gameObject);
    }