From c6e5e0969689086681d970b3d4ee5537316aa81c Mon Sep 17 00:00:00 2001 From: BOT Alex <44818698+MagicBOTAlex@users.noreply.github.com> Date: Sat, 20 Apr 2024 20:12:06 +0200 Subject: [PATCH] Placement system done --- .../PlacementSystem/PlacementManager.cs | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/PlacementSystem/PlacementManager.cs b/Assets/Scripts/PlacementSystem/PlacementManager.cs index 00cd3d7..e408e8c 100644 --- a/Assets/Scripts/PlacementSystem/PlacementManager.cs +++ b/Assets/Scripts/PlacementSystem/PlacementManager.cs @@ -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().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)