From 462caf5cf1e8923724a3bfbce932ad9dd480805c Mon Sep 17 00:00:00 2001 From: "j.mei7" Date: Thu, 17 Mar 2022 19:08:16 +0100 Subject: [PATCH] mousedown if way --- Assets/Scripts/Grid/GridBuildingSystem.cs | 18 +++++++++++++++--- Assets/Scripts/Grid/PlacedObjectTypeSO.cs | 8 ++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/Grid/GridBuildingSystem.cs b/Assets/Scripts/Grid/GridBuildingSystem.cs index 909125c..20cb119 100644 --- a/Assets/Scripts/Grid/GridBuildingSystem.cs +++ b/Assets/Scripts/Grid/GridBuildingSystem.cs @@ -86,14 +86,26 @@ public class GridBuildingSystem : MonoBehaviour selectedGameObjectTransform.gameObject.GetComponent().color = Color.white; } - if (Input.GetMouseButtonDown(0)) + if(selectedPlacedObjectTypeSO.placedObjectType == PlacedObjectTypeSO.PlacedObjectType.WAY) { - PlaceBuilding(); + if (Input.GetMouseButton(0)) + { + PlaceBuilding(); + } } - else if (Input.GetMouseButtonDown(1) || Input.GetKeyDown(KeyCode.Escape)) + else + { + if (Input.GetMouseButtonDown(0)) + { + PlaceBuilding(); + } + } + + if (Input.GetMouseButtonDown(1) || Input.GetKeyDown(KeyCode.Escape)) { DeselectBuilding(); } + } } public void DemolishBuilding(Vector3 position) diff --git a/Assets/Scripts/Grid/PlacedObjectTypeSO.cs b/Assets/Scripts/Grid/PlacedObjectTypeSO.cs index 7ff3763..fbb2165 100644 --- a/Assets/Scripts/Grid/PlacedObjectTypeSO.cs +++ b/Assets/Scripts/Grid/PlacedObjectTypeSO.cs @@ -5,7 +5,11 @@ using UnityEngine; [CreateAssetMenu()] public class PlacedObjectTypeSO : ScriptableObject { - + public enum PlacedObjectType + { + WAY, + BULDING + } public string nameString; public Transform prefab; //public Transform visual; @@ -13,7 +17,7 @@ public class PlacedObjectTypeSO : ScriptableObject public int height; public bool isWalkable = false; public Sprite iconSprite; - + public PlacedObjectType placedObjectType = PlacedObjectType.BULDING; public List GetGridPositionList(Vector2Int offset) {