private void Update() { Vector3 mousePosition = Input.mousePosition; Ray ray = m_Camera.ScreenPointToRay(mousePosition); if (!Physics.Raycast(ray, out RaycastHit hit)) { // mouse doesn't point to anything return; } if (hit.transform != transform) { // mouse doesn't point to the grid return; } if (Input.GetMouseButtonDown(0)) { // click on grid Vector3 hitPosition = hit.point; Vector3 difference = hitPosition - m_Offset; int x = (int)(difference.x / m_Nodesize); int y = (int)(difference.z / m_Nodesize); Vector2Int coords = new Vector2Int(x, y); ProcessClickOnGrid(coords, m_StartCoordinate); if (m_NeedUpdate) { m_Grid.UpdateField(); ResetCache(); } } }