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); }
/// <summary> /// Attempt attacks when we detect a rigidbody collision. /// </summary> private void OnTriggerStay(Collider other) { // EARLY OUT! // // If on cooldown don't attack. if (!this.enabled || _cooldownSeconds > 0f) { return; } // EARLY OUT! // // If the trigger isn't an entity, ignore it. if (!CombatUtils.IsEntity(other.gameObject.layer)) { return; } // EARLY OUT! // // If the collider isn't an enemy, ignore it. var target = other.GetComponent <Entity>(); if (!CombatUtils.IsEnemy(_entity.Owner, target)) { return; } bool didAttack = false; // Only attack if the entity is a type that this unit attacks. if (_entity.AttacksGroundUnits || target.IsBuilding) { didAttack = attemptDirectAttack(target); didAttack |= attemptAreaAttack(target); } if (didAttack) { // Reset cooldown. _cooldownSeconds = _entity.AttackSpeed; // Play attack audio if we have any. if (_animator != null) { _animator.Attack(); } } }