Exemplo n.º 1
0
    public HealthBar GetHealthBar()
    {
        if (availableHealthBars.Count == 0)
        {
            HealthBar newHealthBar = Instantiate(characterInfoPrefab, -Vector3.one * 1000, Quaternion.identity) as HealthBar;
            newHealthBar.transform.SetParent(healthBarsRoot);

            availableHealthBars.Add(newHealthBar);
        }

        HealthBar availableHealthBar = availableHealthBars[0];

        availableHealthBars.RemoveAt(0);
        usedHealthBars.Add(availableHealthBar);
        availableHealthBar.Activate();
        return(availableHealthBar);
    }
Exemplo n.º 2
0
    protected override void OnParticleCollision(GameObject collider)
    {
        base.OnParticleCollision(collider);

        // Check if the collision is actually a defined projectile
        if (collider.CompareTag("Projectile"))
        {
            EventManager.TriggerEvent("ProjectileHit");
            // Get the particle events so we can get the intersect location
            collider.gameObject.SetActive(false);
            List <ParticleCollisionEvent> events = new List <ParticleCollisionEvent>();
            ParticleSystem projectileParticles   = collider.GetComponent <ParticleSystem>();
            projectileParticles.GetCollisionEvents(gameObject, events);

            // Get a pooled hit FX game object and set its location to the intersection point, set active and start reset coroutine
            GameObject hitFx = ObjectPooler.instance.GetPooledHitFx();
            if (hitFx)
            {
                hitFx.transform.position = events[0].intersection;
                hitFx.gameObject.SetActive(true);
                ParticleSystem hitFxParticles = hitFx.GetComponent <ParticleSystem>();
                IEnumerator    coroutine      = ObjectPooler.instance.ReturnParticleToPool(hitFx, hitFxParticles.main.startLifetime.constant);
                ObjectPooler.instance.StartCoroutine(coroutine);
            }

            // Deal damage to the asteroid health
            currentHealth -= SceneController.instance.player.stats.currentProjectileDamage;
            healthBar.Activate();

            // If health is lower than zero, trigger the asteroid explosion chain
            if (currentHealth <= 0f)
            {
                ExplodeAsteroid(5000f, 1000000f);
            }
        }
    }