Exemplo n.º 1
0
    private void OnParticleCollision(GameObject other)
    {
        splatParticles.GetCollisionEvents(other, m_CollisionEvents);
        int count = m_CollisionEvents.Count;

        for (int i = 0; i < count; i++)
        {
            GameObject splat = Instantiate(splatPrefab, m_CollisionEvents[i].intersection, Quaternion.identity);
            splat.transform.SetParent(_splatHolder, true);
            BloodSplitter splatScript = splat.GetComponent <BloodSplitter>();
            splatScript.Initialize(BloodSplitter.SplatLocation.Wall);
        }
    }
Exemplo n.º 2
0
        public void TakeDamage(float value, Vector2 hitPoint)
        {
            health -= value;
            if (health <= 0)
            {
                Destroy(this.gameObject, 1f);
            }

            GameObject splat = Instantiate(splatPrefabs, hitPoint, Quaternion.identity);

            splat.transform.SetParent(_splatHolder, true);
            BloodSplitter splatScript = splat.GetComponent <BloodSplitter>();

            if (ObjectPool.Instance.BloodParticlesPool.Count <= 0)
            {
                GameObject splatParticleSystemGameObject =
                    Instantiate(splatParticlesPrefab, hitPoint, Quaternion.identity);
                splatParticleSystemGameObject.transform.position = hitPoint;
                splatParticleSystemGameObject.GetComponent <ParticleSystem>().Play();
                _splatPSHolder.Add(splatParticleSystemGameObject);
            }
            else
            {
                GameObject splatParticleSystemGameObject = ObjectPool.Instance.BloodParticlesPool.Last();
                splatParticleSystemGameObject.SetActive(true);
                ObjectPool.Instance.BloodParticlesPool.Remove(splatParticleSystemGameObject);
                splatParticleSystemGameObject.transform.position = hitPoint;
                splatParticleSystemGameObject.GetComponent <ParticleSystem>().Play();
                _splatPSHolder.Add(splatParticleSystemGameObject);
            }

            splatScript.Initialize(IsGrounded()
                ? BloodSplitter.SplatLocation.Wall
                : BloodSplitter.SplatLocation.Background);

            if (_splatPSHolder.Count > 0)
            {
                foreach (var ps in _splatPSHolder.ToList())
                {
                    if (ps.GetComponent <ParticleSystem>().isStopped)
                    {
                        ps.SetActive(false);
                        ObjectPool.Instance.BloodParticlesPool.Add(ps);
                        _splatPSHolder.Remove(ps);
                    }
                }
            }
        }