예제 #1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        Projectile projectile = collision.gameObject.GetComponent <Projectile>();

        if (projectile != null && projectile.IsPlayerProjectile != IsPlayerProjectile)
        {
            Destroy(gameObject);
            EffectManager.tinyImpact?.Invoke(transform.position); //spawn explosion effect
            return;
        }
        IDamagable damagable = collision.transform.GetComponent <IDamagable>();

        if (damagable != null)
        {
            if ((damagable.GetType() == typeof(PlayerController) && isPlayerProjectile) ||
                (damagable.GetType() != typeof(PlayerController) && !isPlayerProjectile))
            {
                return;
            }

            EffectManager.mediumExplosion?.Invoke(transform.position); //spawn explosion effect
            Hit = true;
            damagable.TakeDamage(Damage);
            Destroy(gameObject);
        }
    }
예제 #2
0
        private void LookForTarget(IProjectile projectile)
        {
            Collider [] colliders = Physics.OverlapSphere(projectile.Transform.position, _awareRange);

            foreach (Collider collider in colliders)
            {
                IDamagable damagable = collider.GetComponent <IDamagable>();

                if (damagable != null && collider.GetComponent <Destroyable>() == null &&
                    !(damagable.GetType().IsAssignableFrom(projectile.TargetToAvoid.GetType())))
                {
                    projectile.Target = collider.transform;
                    break;
                }
            }
        }
예제 #3
0
        private void ProjectileHitHandle(Collider collider)
        {
            IDamagable damagable = collider.gameObject.GetComponent <IDamagable>();

            if ((damagable != null) && !(damagable.GetType().IsAssignableFrom(_targetToAvoid.GetType())))
            {
                foreach (SpellBehaviour modifier in _modifiers)
                {
                    modifier.ProcessOnHitBehaviour(collider);
                }
                damagable.TakeDamage(_damage);

                SpawnParticles();

                RemoveProjectile();
            }
        }