Example #1
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (((1 << other.gameObject.layer) & collisionLayers) != 0)
        {
            IAudio audioPlayer = ObjectPoolManager.Spawn(audioPlayerPrefab, transform.position).GetComponent <IAudio>();
            audioPlayer.SetUpAudioSource(AudioManager.instance.GetSound("BugsSplat"));
            audioPlayer.PlayAtRandomPitch();

            ObjectPoolManager.Spawn(explosionVFX, transform.position, transform.rotation);
            if (owner)
            {
                owner.Dronekilled(this);
            }
            ObjectPoolManager.Recycle(gameObject);
        }
        if (other.gameObject.CompareTag("Player"))
        {
            if (other.GetComponent <IHurtable>() != null)
            {
                other.GetComponent <IHurtable>().Damage(damage, rb.velocity.normalized, knockBack);
            }
            IAudio audioPlayer = ObjectPoolManager.Spawn(audioPlayerPrefab, transform.position).GetComponent <IAudio>();
            audioPlayer.SetUpAudioSource(AudioManager.instance.GetSound("BugsSplat"));
            audioPlayer.PlayAtRandomPitch();
            ObjectPoolManager.Spawn(explosionVFX, transform.position, transform.rotation);
            if (owner)
            {
                owner.Dronekilled(this);
            }
            ObjectPoolManager.Recycle(gameObject);
        }
        if (other.gameObject.CompareTag("Swarm"))
        {
            Vector2 dir = other.transform.position - transform.position;
            other.GetComponent <Rigidbody2D>().AddForce(dir.normalized * 2.0f, ForceMode2D.Impulse);
        }
    }