Placement system done
This commit is contained in:
parent
e67416be15
commit
c6e5e09696
|
@ -16,7 +16,9 @@ public class TowerPlacementManager : MonoBehaviour
|
|||
|
||||
// Section: Mouse
|
||||
private SlotManager CurrentSelectedSlot;
|
||||
private SlotManager CurrentHovered;
|
||||
private SlotManager CurrentHovered; // Not implemented
|
||||
|
||||
private int CurrentRotation = 0; // 0, 1, 2, 3
|
||||
|
||||
private GameObject SilhouettedObject;
|
||||
|
||||
|
@ -34,6 +36,20 @@ public class TowerPlacementManager : MonoBehaviour
|
|||
OnSpawnGridRequested?.Invoke(this);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.R) && Input.GetKey(KeyCode.LeftShift))
|
||||
{
|
||||
CurrentRotation--;
|
||||
CurrentRotation = CurrentRotation % 4;
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.R))
|
||||
{
|
||||
CurrentRotation++;
|
||||
CurrentRotation = CurrentRotation % 4;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSlotClicked(SlotManager slot, GridManager grid, int x, int y)
|
||||
{
|
||||
slot.gameObject.GetComponentInChildren<Renderer>().material.color = Color.blue;
|
||||
|
@ -61,7 +77,9 @@ public class TowerPlacementManager : MonoBehaviour
|
|||
|
||||
public void SpawnTowerAtSelected(GameObject towerPrefab)
|
||||
{
|
||||
Instantiate(towerPrefab, CurrentSelectedSlot.transform);
|
||||
var spawnedTower = Instantiate(towerPrefab, CurrentSelectedSlot.transform);
|
||||
Quaternion newRotation = Quaternion.AngleAxis(CurrentRotation * 90f, transform.up);
|
||||
spawnedTower.transform.localRotation = newRotation;
|
||||
}
|
||||
|
||||
public void OnSlotHovered(SlotManager slot, GridManager grid, int x, int y)
|
||||
|
@ -69,10 +87,15 @@ public class TowerPlacementManager : MonoBehaviour
|
|||
if (SilhouettedObject == null)
|
||||
SilhouettedObject = ToSilhouette(DebugTowerPrefab);
|
||||
|
||||
// Sets tower rotation
|
||||
Quaternion newRotation = Quaternion.AngleAxis(CurrentRotation * 90f, transform.up);
|
||||
SilhouettedObject.transform.localRotation = newRotation;
|
||||
|
||||
Vector3 offset = DebugTowerPrefab.transform.position;
|
||||
|
||||
//SilhouettedObject.SetActive(true);
|
||||
SilhouettedObject.transform.parent = slot.TowerSpawnPoint.transform;
|
||||
SilhouettedObject.transform.localPosition = Vector3.zero;
|
||||
SilhouettedObject.transform.localRotation = quaternion.identity;
|
||||
SilhouettedObject.transform.localPosition = offset;
|
||||
}
|
||||
|
||||
public void OnSlotUnHovered(SlotManager slot, GridManager grid, int x, int y)
|
||||
|
|
Loading…
Reference in New Issue