Example #1
0
        private void Freeze(List <Collider> enemiesInFreezeArea, float particlesLifeTime)
        {
            Vector3 originFreezePosition = transform.position;
            // Freeze simulation time
            float time = 0;

            foreach (Collider enemyInFreezeArea in enemiesInFreezeArea)
            {
                // Player to enemy distance
                float distance = Vector3.Distance(originFreezePosition, enemyInFreezeArea.transform.position);

                // Compute time when the enemy should be freezed
                time = (distance * particlesLifeTime) / freezeRadius;

                EnemyFreezable freezableEnemy = enemyInFreezeArea.GetComponent <EnemyFreezable>();
                if (freezableEnemy != null)
                {
                    // If enemy is not freezed
                    if (!freezableEnemy.isFreezed)
                    {
                        // Freeze the enemy
                        freezableEnemy.StartCoroutine(freezableEnemy.Freeze(freezeDuration, time));
                    }
                }
            }
        }
Example #2
0
        void Awake()
        {
            // Setting up the references.
            player          = GameObject.FindGameObjectWithTag("Player");
            playerShield    = player.GetComponentInChildren <Shield>();
            enemyFreezable  = GetComponent <EnemyFreezable>();
            anim            = GetComponent <Animator>();
            enemyAudio      = GetComponent <AudioSource>();
            hitParticles    = GetComponentInChildren <ParticleSystem>();
            capsuleCollider = GetComponent <CapsuleCollider>();
            movement        = GetComponent <EnemyMovement>();

            // Setting the current health when the enemy first spawns.
            currentHealth = startingHealth;

            enemies.Add(movement);
        }