diff --git a/Assets/Scripts/PlacementSystem/CameraSlotClickDetect.cs b/Assets/Scripts/PlacementSystem/CameraSlotClickDetect.cs index cbea696..102acfb 100644 --- a/Assets/Scripts/PlacementSystem/CameraSlotClickDetect.cs +++ b/Assets/Scripts/PlacementSystem/CameraSlotClickDetect.cs @@ -27,7 +27,7 @@ public class CameraSlotClickDetect : MonoBehaviour RaycastHit hit; RaycastHit selectHit; - if (Physics.Raycast(ray, out selectHit, Mathf.Infinity, selectLayer) && !GameManager.Instance.IsBuildMode) + if (!GameManager.Instance.IsBuildMode && Physics.Raycast(ray, out selectHit, Mathf.Infinity, selectLayer)) { var tower = selectHit.collider.gameObject.GetComponentInChildren(); if (tower != null) @@ -40,7 +40,7 @@ public class CameraSlotClickDetect : MonoBehaviour Debug.LogWarning("TowerCam scpritet is not assigned, assign in the inspector"); } } - else if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask)) + else if (GameManager.Instance.IsBuildMode && Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask)) { var slotInfo = hit.collider.gameObject.GetComponentInParent(); slotInfo.OnClick(); @@ -58,23 +58,24 @@ public class CameraSlotClickDetect : MonoBehaviour Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; - if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask)) - { - var slotInfo = hit.collider.gameObject.GetComponentInParent(); - - if (PrevHoveredSlot != null && PrevHoveredSlot != slotInfo) + if (GameManager.Instance.IsBuildMode) + if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask)) { - PrevHoveredSlot.OnUnHovered(); - } + var slotInfo = hit.collider.gameObject.GetComponentInParent(); - slotInfo.OnHovered(); - PrevHoveredSlot = slotInfo; - } - else - { - if (PrevHoveredSlot != null) - PrevHoveredSlot.OnUnHovered(); - PrevHoveredSlot = null; - } + if (PrevHoveredSlot != null && PrevHoveredSlot != slotInfo) + { + PrevHoveredSlot.OnUnHovered(); + } + + slotInfo.OnHovered(); + PrevHoveredSlot = slotInfo; + } + else + { + if (PrevHoveredSlot != null) + PrevHoveredSlot.OnUnHovered(); + PrevHoveredSlot = null; + } } }