Tower cannot stack at slots

This commit is contained in:
BOT Alex 2024-04-21 11:43:45 +02:00
parent 54ad0c1afe
commit e716f9ff15
3 changed files with 17 additions and 11 deletions

View File

@ -13,17 +13,10 @@ public class GridManager : MonoBehaviour
[DoNotSerialize] public List<GameObject> SpawnedSlots = new(); [DoNotSerialize] public List<GameObject> SpawnedSlots = new();
/// <summary>
/// Not implimented
/// </summary>
[DoNotSerialize] public string[,] GridStates;
private void OnEnable() private void OnEnable()
{ {
TowerPlacementManager.OnSpawnGridRequested += SpawnSlots; TowerPlacementManager.OnSpawnGridRequested += SpawnSlots;
TowerPlacementManager.OnGridDeleteRequested += DeleteGrid; TowerPlacementManager.OnGridDeleteRequested += DeleteGrid;
GridStates = new string[GridSize.x, GridSize.y];
} }
private void OnDisable() private void OnDisable()

View File

@ -93,8 +93,7 @@ public class TowerPlacementManager : MonoBehaviour
// slot.gameObject.GetComponentInChildren<Renderer>().material.color = Color.blue; // slot.gameObject.GetComponentInChildren<Renderer>().material.color = Color.blue;
OnSelectSlot(slot); OnSelectSlot(slot);
SpawnTowerAtSelected(SelectedTowerPrefab); SpawnTowerAtSelected(slot, SelectedTowerPrefab);
Debug.Log("TAX");
GameManager.Instance.Balance.Value -= SelectedTowerInfo.price; GameManager.Instance.Balance.Value -= SelectedTowerInfo.price;
} }
@ -115,13 +114,17 @@ public class TowerPlacementManager : MonoBehaviour
prevSlot.gameObject.GetComponentInChildren<Renderer>().material.color = Color.white; prevSlot.gameObject.GetComponentInChildren<Renderer>().material.color = Color.white;
} }
public void SpawnTowerAtSelected(GameObject towerPrefab) public void SpawnTowerAtSelected(SlotManager slotRef, GameObject towerPrefab)
{ {
var spawnedTower = Instantiate(towerPrefab, CurrentSelectedSlot.transform); var spawnedTower = Instantiate(towerPrefab, CurrentSelectedSlot.transform);
Quaternion newRotation = Quaternion.AngleAxis(CurrentRotation * 90f, transform.up); Quaternion newRotation = Quaternion.AngleAxis(CurrentRotation * 90f, transform.up);
spawnedTower.transform.localRotation = newRotation; spawnedTower.transform.localRotation = newRotation;
spawnedTower.GetComponent<Tower>().Placed(); Tower towerScript = spawnedTower.GetComponent<Tower>();
slotRef.TowerHealth = towerScript.GetComponent<HealthComponent>();
towerScript.Placed();
FinishBuild(); FinishBuild();
} }

View File

@ -9,6 +9,10 @@ public class SlotManager : MonoBehaviour
public int x; public int x;
public int y; public int y;
public HealthComponent TowerHealth;
public bool IsOccupied => TowerHealth.TryGetComponent(out HealthComponent _);
public Transform TowerSpawnPoint; public Transform TowerSpawnPoint;
/// <summary> /// <summary>
@ -21,16 +25,22 @@ public class SlotManager : MonoBehaviour
public void OnClick() public void OnClick()
{ {
if (IsOccupied) return;
OnSlotClicked?.Invoke(this, spawnerRef, x, y); OnSlotClicked?.Invoke(this, spawnerRef, x, y);
} }
public void OnHovered() public void OnHovered()
{ {
if (IsOccupied) return;
OnSlotHovered?.Invoke(this, spawnerRef, x, y); OnSlotHovered?.Invoke(this, spawnerRef, x, y);
} }
public void OnUnHovered() public void OnUnHovered()
{ {
if (IsOccupied) return;
OnSlotUnHovered?.Invoke(this, spawnerRef, x, y); OnSlotUnHovered?.Invoke(this, spawnerRef, x, y);
} }
} }