using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Tilemaps; public class GridController : MonoBehaviour { [SerializeField] Tilemap highlightMap = null; [SerializeField] TileBase hilightTile = null; [SerializeField] TileBase hilightMovementAreaTile = null; private IAction hilightAction; public IAction HilightAction { get => hilightAction; set => hilightAction = value; } // Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0) && hilightAction != null && hilightAction.HilightEnabled) { PaintMovementArea(RoundManager.GetInstance().activeCreature); Vector3Int clickedPos = GetMousePosition(); highlightMap.SetTile(clickedPos, hilightTile); hilightAction.HilightEnabled = false; // TODO needs better handling.. Should be in MoveAction??? YesNoDilougueUI.Instance.ShowDialog("Are you sure you want to move here?", () => { Debug.Log("YES PRESSED"); /* Confirm the move and paint the path to take. */}, () => { Debug.Log("NO PRESSED"); highlightMap.SetTile(clickedPos, null); hilightAction.HilightEnabled = true; }); } } Vector3Int GetMousePosition() { Vector3 mousePos = Input.mousePosition; mousePos.z = -Camera.main.transform.position.z; Vector3 worldPoint = Camera.main.ScreenToWorldPoint(mousePos); return GameManagerScript.GetInstance().TileMap.WorldToCell(worldPoint); } public void PaintMovementArea(Creature toMove) { Vector3 startPos = toMove.transform.position; int movementInSquares = Mathf.FloorToInt(toMove.GetComponent().movementRate / 5); //Physics2D.OverlapCircle(startPos); Maybe this one.. don't know Collider2D[] collider2Ds = Physics2D.OverlapCircleAll(new Vector2(startPos.x, startPos.y), movementInSquares, LayerMask.NameToLayer("Ground")); Debug.Log("Hitting " + collider2Ds.Length); } }