diff --git a/Assets/Scripts/Drag&Drop/DraggablePlaceholder.cs b/Assets/Scripts/Drag&Drop/DraggablePlaceholder.cs index a7c0898..61cc41a 100644 --- a/Assets/Scripts/Drag&Drop/DraggablePlaceholder.cs +++ b/Assets/Scripts/Drag&Drop/DraggablePlaceholder.cs @@ -1,3 +1,4 @@ +using System; using System.Collections; using System.Collections.Generic; using System.Linq; @@ -20,6 +21,8 @@ public abstract class DraggablePlaceholder : MonoBehaviour protected Rect _lvlBoundsCache; protected bool _canBePlacedHere; + protected static bool alreadyHasUnit = false; + private List _outlineRenderers = new List(); public List OutlineRenderers { @@ -50,14 +53,15 @@ public abstract class DraggablePlaceholder : MonoBehaviour { if (!Input.GetMouseButton(0)) { - if (_canBePlacedHere) + if (_canBePlacedHere && !alreadyHasUnit) { ResourceManager.Instance.Remove(Rock, Wood, Food); Place(); + alreadyHasUnit = true; } Destroy(gameObject); } - + alreadyHasUnit = AlreadyHasUnit(); _canBePlacedHere = CanBePlacedHere(); UpdatePosition(); @@ -96,6 +100,11 @@ public abstract class DraggablePlaceholder : MonoBehaviour && ResourceManager.Instance.EnoughFor(Rock, Wood, Food); } + public virtual bool AlreadyHasUnit() + { + return !_lvlBoundsCache.Contains(transform.position); + } + /// /// how your character will appear depending on the validity of the tile you want to put them on
/// default behaviour is changes color of all sprite renderers of the Outline Transform to red if invalid, green otherwise diff --git a/Assets/Scripts/Drag&Drop/ObjectPlaceholder.cs b/Assets/Scripts/Drag&Drop/ObjectPlaceholder.cs index 9fbe0b7..b02a93f 100644 --- a/Assets/Scripts/Drag&Drop/ObjectPlaceholder.cs +++ b/Assets/Scripts/Drag&Drop/ObjectPlaceholder.cs @@ -16,7 +16,7 @@ public class ObjectPlaceholder : DraggablePlaceholder return !positionIsCollidable && _lvlBoundsCache.Contains(transform.position) && ResourceManager.Instance.EnoughFor(Rock, Wood, Food) - && (Prefab.GetComponent() - || ResourceManager.Instance.EnoughPopulationFor(defaultUnitCost)); + && (Prefab.GetComponent() + || ResourceManager.Instance.EnoughPopulationFor(defaultUnitCost)) ; } } \ No newline at end of file diff --git a/Assets/Scripts/Drag&Drop/TilePlaceholder.cs b/Assets/Scripts/Drag&Drop/TilePlaceholder.cs index a848ad7..9ac48ca 100644 --- a/Assets/Scripts/Drag&Drop/TilePlaceholder.cs +++ b/Assets/Scripts/Drag&Drop/TilePlaceholder.cs @@ -6,5 +6,6 @@ public class TilePlaceholder : DraggablePlaceholder public override void Place() { LevelManager.Instance.DynamicTilemap.SetTile(Vector3Int.RoundToInt(transform.position), Tile); + alreadyHasUnit = true; } } \ No newline at end of file