diff --git a/Assets/Scripts/Drag&Drop/GameObjectPlacementButton.cs b/Assets/Scripts/Drag&Drop/GameObjectPlacementButton.cs index fcac9d7..af39edb 100644 --- a/Assets/Scripts/Drag&Drop/GameObjectPlacementButton.cs +++ b/Assets/Scripts/Drag&Drop/GameObjectPlacementButton.cs @@ -12,7 +12,7 @@ public class GameObjectPlacementButton : UnitPlacementButton foreach (var comp in instance.transform.GetAllComponents()) Destroy(comp); foreach (var comp in instance.transform.GetAllComponents()) Destroy(comp); - var placeholder = instance.AddComponent(); + var placeholder = instance.AddComponent(); placeholder.Prefab = _prefab; var outline = new GameObject("Outline"); diff --git a/Assets/Scripts/Drag&Drop/ObjectDraggablePlaceholder.cs b/Assets/Scripts/Drag&Drop/ObjectDraggablePlaceholder.cs deleted file mode 100644 index efa042f..0000000 --- a/Assets/Scripts/Drag&Drop/ObjectDraggablePlaceholder.cs +++ /dev/null @@ -1,10 +0,0 @@ -using UnityEngine; - -public class ObjectDraggablePlaceholder : DraggablePlaceholder -{ - public GameObject Prefab { get; set; } - public override void Place() - { - Prefab.Create(transform.position); - } -} \ No newline at end of file diff --git a/Assets/Scripts/Drag&Drop/ObjectPlaceholder.cs b/Assets/Scripts/Drag&Drop/ObjectPlaceholder.cs new file mode 100644 index 0000000..20da1a5 --- /dev/null +++ b/Assets/Scripts/Drag&Drop/ObjectPlaceholder.cs @@ -0,0 +1,18 @@ +using UnityEngine; + +public class ObjectPlaceholder : DraggablePlaceholder +{ + public GameObject Prefab { get; set; } + public override void Place() + { + Prefab.Create(transform.position); + } + public override bool CanBePlacedHere() + { + var objsOnPosition = LevelManager.Instance.GetAll(obj => obj.Position.IsContainedIn(transform.position)); + var positionContainsFarm = objsOnPosition.Exists(obj => obj.Name.ToLower().Contains("farm")); + + //either no object, or object is farm + return objsOnPosition.Count == 0 || (objsOnPosition.Count == 1 && positionContainsFarm); + } +} \ No newline at end of file diff --git a/Assets/Scripts/Drag&Drop/ObjectDraggablePlaceholder.cs.meta b/Assets/Scripts/Drag&Drop/ObjectPlaceholder.cs.meta similarity index 100% rename from Assets/Scripts/Drag&Drop/ObjectDraggablePlaceholder.cs.meta rename to Assets/Scripts/Drag&Drop/ObjectPlaceholder.cs.meta