コード例 #1
0
    public void Hit(bool isHitSourceBall = true)
    {
        if (_isHit)
        {
            return;
        }
        _isHit = true;

        #region Experimental extra feature
        if (isHitSourceBall && _type == BlockType.Gem)
        {
            GameObject gemBurstFx = ObjectPooler.Instance.GetPooledObject(ObjectPoolItems.GemBurstFx, true);
            gemBurstFx.transform.position = gameObject.transform.position;
            _tower.RemoveBlock(this, _levelRef);
            gameObject.SetActive(false);
            return;
        }
        #endregion


        ///hit cascade calculation:  Get the nearby collider, check if same color
        Collider[] hitColliders = Physics.OverlapSphere(_centerPos, _overlapSphereRadius);
        int        i            = 0;
        while (i < hitColliders.Length)
        {
            if (hitColliders[i].transform.parent == null)
            {
                i++;
                continue;
            }
            BlockScript adjacentBlock = hitColliders[i].transform.parent.GetComponent <BlockScript>();
            if (adjacentBlock != null && adjacentBlock.CompareColor(_renderer.sharedMaterial)) //._renderer.sharedMaterial == _renderer.sharedMaterial)
            {
                adjacentBlock.Hit(false);
            }
            i++;
        }

        _tower.RemoveBlock(this, _levelRef);
        GameObject burstFx = ObjectPooler.Instance.GetPooledObject(ObjectPoolItems.BurstFx, true);
        burstFx.transform.position = gameObject.transform.position;

        //TODO : cache components in object pooler
        ParticleSystem.MainModule settings = burstFx.GetComponent <ParticleSystem>().main;
        settings.startColor = _renderer.sharedMaterial.color;

        gameObject.SetActive(false);
    }
コード例 #2
0
    private void OnCollisionEnter(Collision collision)
    {
        if (_isObjectHit)
        {
            return;
        }
        BlockScript block = collision.gameObject.GetComponent <BlockScript>();

        if (block != null && block.CompareColor(_renderer.sharedMaterial))
        {
            AndroidVibration.Vibrate(20);
            block.Hit();
            gameObject.SetActive(false);
        }
        _isObjectHit = true;
    }