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();
|
[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()
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue