コード例 #1
0
    protected void OnTriggerEnter(Collider coll)
    {
        if (coll.tag == "EnemyBullet")
        {
            if (gameObject.layer == LayerMask.NameToLayer("EnemyEntity"))
            {
                return;
            }

            ParticleFactory.GetInstance().CreateOnceParticle <ParticleExplosion>(coll.gameObject.GetComponent <Collider>().ClosestPointOnBounds(transform.position))
            .SetExplosionParticleNumber(10)
            .SetMinExplosionDistance(1.0f)
            .SetMaxExplosionDistance(3.0f)
            .SetExplosionParticleLifeTime(0.4f)
            .SetExplosionParticleColor(new Color(Random.Range(0.5f, 1.0f), Random.Range(0.5f, 1.0f), Random.Range(0.5f, 1.0f)))
            .Play();

            if (m_Core.isPenetrable() == false)
            {
                Destroy(coll.gameObject.transform.parent.gameObject);
            }

            Material material = GetComponentInChildren <MeshRenderer>().material;

            if (m_Core.IsInvincible() == false)
            {
                m_Core.SetHp <EntityCore>(m_Core.GetHp() - ManagerPool.GetInstance().GetManager <PlayerManager>().GetPlayerGun().GetBulletDamage());
            }

            if (m_Core.GetHp() <= 0)
            {
                PlayerManager playerManager = ManagerPool.GetInstance().GetManager <PlayerManager>();
                playerManager.SetPlayerScore(playerManager.GetPlayerScore() + m_Core.GetScore());

                ParticleFactory.GetInstance().CreateOnceParticle <ParticleExplosion>(gameObject.transform.position)
                .SetExplosionParticleColor(new Color(Random.Range(0.5f, 1.0f), Random.Range(0.5f, 1.0f), Random.Range(0.5f, 1.0f)))
                .Play();
                Destroy(gameObject);

                material.DOKill();
            }
            else
            {
                DOTween.Sequence()
                .Append(material.DOColor(Color.white, 0.05f))
                .Append(material.DOColor(m_Core.GetColor(), 0.05f));
            }
        }

        if (coll.tag == "PlayerBullet")
        {
            if (gameObject.layer == LayerMask.NameToLayer("PlayerEntity"))
            {
                return;
            }

            ParticleFactory.GetInstance().CreateOnceParticle <ParticleExplosion>(coll.gameObject.GetComponent <Collider>().ClosestPointOnBounds(transform.position))
            .SetExplosionParticleNumber(10)
            .SetMinExplosionDistance(1.0f)
            .SetMaxExplosionDistance(3.0f)
            .SetExplosionParticleLifeTime(0.4f)
            .SetExplosionParticleColor(new Color(Random.Range(0.5f, 1.0f), Random.Range(0.5f, 1.0f), Random.Range(0.5f, 1.0f)))
            .Play();

            if (m_Core.isPenetrable() == false)
            {
                Destroy(coll.gameObject.transform.parent.gameObject);
            }

            Material material = GetComponentInChildren <MeshRenderer>().material;

            if (m_Core.IsInvincible() == false)
            {
                m_Core.SetHp <EntityCore>(m_Core.GetHp() - ManagerPool.GetInstance().GetManager <PlayerManager>().GetPlayerGun().GetBulletDamage());
            }

            if (m_Core.GetHp() <= 0)
            {
                PlayerManager playerManager = ManagerPool.GetInstance().GetManager <PlayerManager>();
                ItemManager   itemManager   = ManagerPool.GetInstance().GetManager <ItemManager>();

                playerManager.SetPlayerScore(playerManager.GetPlayerScore() + m_Core.GetScore());

                ParticleFactory.GetInstance().CreateOnceParticle <ParticleExplosion>(gameObject.transform.position)
                .SetExplosionParticleColor(new Color(Random.Range(0.5f, 1.0f), Random.Range(0.5f, 1.0f), Random.Range(0.5f, 1.0f)))
                .Play();

                float randNum = Random.Range(0.0f, 1000.0f);
                if (randNum <= 1000.0f)
                {
                    ItemType itemType = (ItemType)Random.Range(1, Enum.GetValues(typeof(ItemType)).Cast <int>().Max() + 1);
                    itemManager.SpawnItem(itemType, gameObject.transform.position);
                }

                Destroy(gameObject);
                material.DOKill();
            }
            else
            {
                if (m_Core.IsInvincible() == false)
                {
                    DOTween.Sequence()
                    .Append(material.DOColor(Color.white, 0.05f))
                    .Append(material.DOColor(m_Core.GetColor(), 0.05f));
                }
            }
        }
    }