Tower cannot stack at slots
This commit is contained in:
parent
54ad0c1afe
commit
e716f9ff15
|
@ -13,17 +13,10 @@ public class GridManager : MonoBehaviour
|
|||
|
||||
[DoNotSerialize] public List<GameObject> SpawnedSlots = new();
|
||||
|
||||
/// <summary>
|
||||
/// Not implimented
|
||||
/// </summary>
|
||||
[DoNotSerialize] public string[,] GridStates;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
TowerPlacementManager.OnSpawnGridRequested += SpawnSlots;
|
||||
TowerPlacementManager.OnGridDeleteRequested += DeleteGrid;
|
||||
|
||||
GridStates = new string[GridSize.x, GridSize.y];
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
|
|
|
@ -93,8 +93,7 @@ public class TowerPlacementManager : MonoBehaviour
|
|||
// slot.gameObject.GetComponentInChildren<Renderer>().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<Renderer>().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<Tower>().Placed();
|
||||
Tower towerScript = spawnedTower.GetComponent<Tower>();
|
||||
|
||||
slotRef.TowerHealth = towerScript.GetComponent<HealthComponent>();
|
||||
|
||||
towerScript.Placed();
|
||||
FinishBuild();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue