Stopped accidental building
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
|
||||||
|
|
||||||
namespace Fruitomation.Game
|
namespace Fruitomation.Game
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ namespace Fruitomation.UI
|
|||||||
private readonly List<Collider2D> Colliders = new();
|
private readonly List<Collider2D> Colliders = new();
|
||||||
|
|
||||||
private float StartOfMouseClick;
|
private float StartOfMouseClick;
|
||||||
|
private bool MouseOnGrid;
|
||||||
|
|
||||||
private void UpdatePosition()
|
private void UpdatePosition()
|
||||||
{
|
{
|
||||||
@@ -54,6 +55,8 @@ namespace Fruitomation.UI
|
|||||||
Math.Clamp(p4.x, 0, 95), // size.x - 1
|
Math.Clamp(p4.x, 0, 95), // size.x - 1
|
||||||
Math.Clamp(p4.y, 0, 48) // size.y - 1
|
Math.Clamp(p4.y, 0, 48) // size.y - 1
|
||||||
);
|
);
|
||||||
|
|
||||||
|
MouseOnGrid = GridPosition == p4;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
@@ -159,7 +162,7 @@ namespace Fruitomation.UI
|
|||||||
BuildingPreview.rectTransform.anchoredPosition = p4;
|
BuildingPreview.rectTransform.anchoredPosition = p4;
|
||||||
|
|
||||||
//
|
//
|
||||||
if (Input.GetMouseButtonDown(0))
|
if (Input.GetMouseButtonDown(0) && MouseOnGrid)
|
||||||
{
|
{
|
||||||
BuildingManager.AddBuildingAt(p1, BuildingPrefab);
|
BuildingManager.AddBuildingAt(p1, BuildingPrefab);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user