From e716f9ff15c9029553f3769c0bf41aeadd47532a Mon Sep 17 00:00:00 2001 From: BOT Alex <44818698+MagicBOTAlex@users.noreply.github.com> Date: Sun, 21 Apr 2024 11:43:45 +0200 Subject: [PATCH] Tower cannot stack at slots --- Assets/Scripts/PlacementSystem/GridManager.cs | 7 ------- Assets/Scripts/PlacementSystem/PlacementManager.cs | 11 +++++++---- Assets/Scripts/PlacementSystem/SlotManager.cs | 10 ++++++++++ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Assets/Scripts/PlacementSystem/GridManager.cs b/Assets/Scripts/PlacementSystem/GridManager.cs index df56b32..6c1d698 100644 --- a/Assets/Scripts/PlacementSystem/GridManager.cs +++ b/Assets/Scripts/PlacementSystem/GridManager.cs @@ -13,17 +13,10 @@ public class GridManager : MonoBehaviour [DoNotSerialize] public List SpawnedSlots = new(); - /// - /// Not implimented - /// - [DoNotSerialize] public string[,] GridStates; - private void OnEnable() { TowerPlacementManager.OnSpawnGridRequested += SpawnSlots; TowerPlacementManager.OnGridDeleteRequested += DeleteGrid; - - GridStates = new string[GridSize.x, GridSize.y]; } private void OnDisable() diff --git a/Assets/Scripts/PlacementSystem/PlacementManager.cs b/Assets/Scripts/PlacementSystem/PlacementManager.cs index 94ca4fe..f24d0fb 100644 --- a/Assets/Scripts/PlacementSystem/PlacementManager.cs +++ b/Assets/Scripts/PlacementSystem/PlacementManager.cs @@ -93,8 +93,7 @@ public class TowerPlacementManager : MonoBehaviour // slot.gameObject.GetComponentInChildren().material.color = Color.blue; OnSelectSlot(slot); - SpawnTowerAtSelected(SelectedTowerPrefab); - Debug.Log("TAX"); + SpawnTowerAtSelected(slot, SelectedTowerPrefab); GameManager.Instance.Balance.Value -= SelectedTowerInfo.price; } @@ -115,13 +114,17 @@ public class TowerPlacementManager : MonoBehaviour prevSlot.gameObject.GetComponentInChildren().material.color = Color.white; } - public void SpawnTowerAtSelected(GameObject towerPrefab) + public void SpawnTowerAtSelected(SlotManager slotRef, GameObject towerPrefab) { var spawnedTower = Instantiate(towerPrefab, CurrentSelectedSlot.transform); Quaternion newRotation = Quaternion.AngleAxis(CurrentRotation * 90f, transform.up); spawnedTower.transform.localRotation = newRotation; - spawnedTower.GetComponent().Placed(); + Tower towerScript = spawnedTower.GetComponent(); + + slotRef.TowerHealth = towerScript.GetComponent(); + + towerScript.Placed(); FinishBuild(); } diff --git a/Assets/Scripts/PlacementSystem/SlotManager.cs b/Assets/Scripts/PlacementSystem/SlotManager.cs index fef6461..d206d21 100644 --- a/Assets/Scripts/PlacementSystem/SlotManager.cs +++ b/Assets/Scripts/PlacementSystem/SlotManager.cs @@ -9,6 +9,10 @@ public class SlotManager : MonoBehaviour public int x; public int y; + public HealthComponent TowerHealth; + + public bool IsOccupied => TowerHealth.TryGetComponent(out HealthComponent _); + public Transform TowerSpawnPoint; /// @@ -21,16 +25,22 @@ public class SlotManager : MonoBehaviour public void OnClick() { + if (IsOccupied) return; + OnSlotClicked?.Invoke(this, spawnerRef, x, y); } public void OnHovered() { + if (IsOccupied) return; + OnSlotHovered?.Invoke(this, spawnerRef, x, y); } public void OnUnHovered() { + if (IsOccupied) return; + OnSlotUnHovered?.Invoke(this, spawnerRef, x, y); } }