Example #1
0
    private void OnTriggerEnter(Collider other)
    {
        // EARLY OUT! //
        // If the trigger isn't on an impact layer, ignore it.
        if (_isCollided || !CombatUtils.IsProjectileCollider(other.gameObject.layer))
        {
            return;
        }

        // EARLY OUT! //
        // If the collider is a friendly entity, early out.
        if (CombatUtils.IsEntity(other.gameObject.layer) && !CombatUtils.IsEnemy(_creator.Owner, other))
        {
            return;
        }

        _isCollided = true;

        var card = SL.Get <Config>().GetCardByName(_entityToSpawn);

        if (card != null)
        {
            card.SpawnChargeSeconds = 0;
            var unit = Entity.SpawnFromDefinition(_creator.Owner, card, transform.position.ZeroY(), isFromPlayersHand: false);
            _creator.Owner.RotateForPlayer(unit.gameObject);
        }
        else
        {
            Debug.LogWarning("Can't find card: " + card.Name);
        }

        // Destroy the shell.
        Destroy(gameObject);
    }
    private void OnTriggerEnter(Collider other)
    {
        // EARLY OUT! //
        // If the trigger isn't on an impact layer, ignore it.
        if (!CombatUtils.IsProjectileCollider(other.gameObject.layer))
        {
            return;
        }

        // EARLY OUT! //
        // If the collider is a friendly entity, early out.
        if (CombatUtils.IsEntity(other.gameObject.layer) && !CombatUtils.IsEnemy(_owner, other))
        {
            return;
        }

        // Collect all the colliders in a sphere from the shell's current position to a radius of the explosion radius.
        Collider[] colliders = Physics.OverlapSphere(transform.position, _explosionRadius, CombatUtils.EntityMask);

        for (int i = 0; i < colliders.Length; i++)
        {
            Entity targetEntity = colliders[i].GetComponent <Entity> ();

            // If it's an enemy unit, do damage to it.
            if (CombatUtils.IsEnemy(_owner, targetEntity))
            {
                targetEntity.TakeDamage(_areaDamage);
            }
        }

        if (_explosionParticlePrefab != null)
        {
            var explosion = Utils.Instantiate(_explosionParticlePrefab, transform.position, transform.rotation);

            // Play the particle system.
            explosion.Play();

            // Once the particles have finished, destroy the gameobject they are on.
            Destroy(explosion.gameObject, explosion.main.duration);
        }

        if (_explosionAudio != null)
        {
            // Play the explosion sound effect.
            _explosionAudio.Play();
        }


        // Destroy the shell.
        Destroy(gameObject);
    }