mirror of
https://github.com/ryzij/Cube-Tower-Defense.git
synced 2026-07-14 01:56:57 +00:00
Добавил возможность удалять путь во время строительства
This commit is contained in:
@@ -16,8 +16,11 @@ public class BlockDestoyReward : MonoBehaviour
|
||||
_sandPathBuildService.OnBlockDestroy -= OnBlockDestroy;
|
||||
}
|
||||
|
||||
private void OnBlockDestroy(BlockScript _)
|
||||
private void OnBlockDestroy(BlockScript block)
|
||||
{
|
||||
_wallet.AddMoney(_reward);
|
||||
if (block.Type == BlockScript.BlockType.Grass)
|
||||
_wallet.AddMoney(_reward);
|
||||
else if (block.Type == BlockScript.BlockType.Sand)
|
||||
_wallet.TakeMoney(_reward);
|
||||
}
|
||||
}
|
||||
@@ -60,17 +60,37 @@ public class SandPathBuildService : MonoBehaviour
|
||||
{
|
||||
var block = _blocksInPath[i];
|
||||
Instantiate(_grassBlockPrefab, block.transform.position, block.transform.localRotation, block.transform.parent);
|
||||
Destroy(block.gameObject);
|
||||
DestroyBlock(block);
|
||||
}
|
||||
|
||||
_blocksInPath.Clear();
|
||||
InitBlocks();
|
||||
}
|
||||
|
||||
public void ResetLastBlock()
|
||||
{
|
||||
if (_predefinedBlocks.Contains(_currentBlock))
|
||||
return;
|
||||
|
||||
_blocksInPath.Remove(_currentBlock);
|
||||
Instantiate(_grassBlockPrefab,
|
||||
_currentBlock.transform.position,
|
||||
_currentBlock.transform.localRotation,
|
||||
_currentBlock.transform.parent);
|
||||
DestroyBlock(_currentBlock);
|
||||
|
||||
_currentBlock = _blocksInPath.LastOrDefault();
|
||||
}
|
||||
|
||||
private void OnBlockDetected(BlockScript block)
|
||||
{
|
||||
if (_gameManager.CurrentState != GameManager.GameState.BuildingPath)
|
||||
return;
|
||||
if (block == _currentBlock)
|
||||
{
|
||||
ResetLastBlock();
|
||||
return;
|
||||
}
|
||||
if (!block.CompareTag("GrassBlock") ||
|
||||
!_currentBlock.GetNeighbors().Contains(block) ||
|
||||
block.GetNeighbors().Count((o) => o.Type == BlockScript.BlockType.Sand) > 1)
|
||||
|
||||
@@ -5,7 +5,6 @@ public class GameMenuButtons : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameManager _gameManager;
|
||||
[SerializeField] private SandPathBuildService _sandPathBuildService;
|
||||
[SerializeField] private Wallet _wallet;
|
||||
[SerializeField] private Button _mainMenuButton;
|
||||
[SerializeField] private Button _nextLevelButton;
|
||||
[SerializeField] private Button _resetPathButton;
|
||||
@@ -49,7 +48,6 @@ public class GameMenuButtons : MonoBehaviour
|
||||
private void OnResetButtonClick()
|
||||
{
|
||||
_sandPathBuildService.ResetPath();
|
||||
_wallet.TakeMoney(_wallet.Money);
|
||||
_gameManager.CurrentState = GameManager.GameState.BuildingPath;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user