示例#1
0
    public void DestroyBlock(GameObject receivedBlock)
    {
        if (!receivedBlock.CompareTag("Block"))
        {
            return;
        }

        Destroy(receivedBlock);
        _blockCount--;

        AudioManager.Instance.PlayBlockDestroyedSound();

        var particles = Instantiate(DestroyingParticles, receivedBlock.transform.position, receivedBlock.transform.rotation);

        particles.GetComponent <ParticleSystem>().Play();
        Destroy(particles, 1f);

        _doubleBallBonus.Execute();
        _slowMoBallBonus.Execute();

        var receivedBlockId = receivedBlock.GetComponent <BlockId>().Id;

        var blockForRemove = CurrentLevelState.BlocksList.FirstOrDefault(t => t.Id == receivedBlockId);

        CurrentLevelState.BlocksList.Remove(blockForRemove);

        var amount = CurrentLevel.BlocksList
                     .Where(t => t.Id == receivedBlockId)
                     .Select(t => t.BlockScoreCost).FirstOrDefault();


        Score.AddAmountToScore(amount);

        if (_blockCount <= 0)
        {
            GameFinishedEvent?.Invoke();
        }
    }