I want to make my mouse cursor shows the current tile's coordinates (the tile x and y) and display it on debug log, here is my current code
getCursorCoordinate.cs
using UnityEngine;
using System.Collections;
public class getCursorCoordinate : MonoBehaviour {
int xx = 0; int yy = 0;
public tk2dTileMap tilemap;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI(){
Event e = Event.current;
if (e.type == EventType.MouseDrag && e.button == 0 && e.isMouse)
{
tilemap.GetTileAtPosition(tk2dCamera.Instance.camera.ScreenToWorldPoint(e.mousePosition), out xx, out yy);
Debug.Log("x:" + xx + "|y:" + yy);
}
}
}
I tried to check the most bottom left tile (where it should be 0, 0) but it shows the wrong tile coordinate (0, 28). Can anyone help me, thanks!