コード例 #1
0
        /// <summary>
        /// Returns the tile the mouse is currently hovering over
        /// </summary>
        private GridTile DetectHoveredTile(GridTile[,] tileGrid, Vector3 screenPointRaySource)
        {
            var ray         = _mainCamera.ScreenPointToRay(screenPointRaySource);
            var raycastHits = new RaycastHit[MaxRaycastHits];

            Physics.RaycastNonAlloc(ray, raycastHits);
            var hitTileTransform = raycastHits.FirstOrDefault(x => !ReferenceEquals(x.transform, null) && x.transform.CompareTag("Tile")).transform;

            if (ReferenceEquals(hitTileTransform, null))
            {
                return(null);
            }
            var position = hitTileTransform.position;

            return(tileGrid[(int)position.x, (int)position.y]);
        }