/** * Depending on the current situation with the selected object and where our mouse is hovering, * different cursors will need to be displayed */ private void setCursor(Selectable selectedObject) { // We only need to set custom cursors if a friendly ant unit is currently selected if (selectedObject != null && selectedObject.GetComponent<AntUnit>() != null && selectedObject.isNeutralOrFriendly()) { Selectable hoveredObject = getSelectableAtPosition((Vector2) Camera.main.ScreenToWorldPoint(Input.mousePosition)); if (hoveredObject != null) { // If a Tile is the topMostSelectable then we should display a 'move' type cursor if (hoveredObject.GetComponent<Tile>() != null) { if (hoveredObject.gameObject.layer != LayerMask.NameToLayer("Tile")) { Cursor.SetCursor(moveToDisabledCursor, Vector2.zero, CursorMode.Auto); } else { Cursor.SetCursor(moveToCursor, Vector2.zero, CursorMode.Auto); } return; } if (hoveredObject.GetComponent<Scentpath>() != null) { Cursor.SetCursor(moveToCursor, Vector2.zero, CursorMode.Auto); return; } // If Food is the topMostSelectable and we currently have a Gatherer selected, display a 'gather' type cursor if (selectedObject.GetComponent<GathererUnit>() != null && hoveredObject.GetComponent<Food>() != null) { Cursor.SetCursor(gatherCursor, Vector2.zero, CursorMode.Auto); return; } // If an AntUnit is the topMostSelectable and we currently have a Warrior selected, display an 'attack' type cursor if (selectedObject.GetComponent<WarriorUnit>() != null && hoveredObject.GetComponent<Attackable>() != null && !hoveredObject.isNeutralOrFriendly()) { Cursor.SetCursor(attackCursor, Vector2.zero, CursorMode.Auto); return; } // If a ruined anthill is the topMostSelectable and we currently have a Queen selected, display a 'build' type cursor if (selectedObject.GetComponent<QueenUnit>() != null && hoveredObject.GetComponent<DeadAnthill>() != null) { Cursor.SetCursor(buildCursor, Vector2.zero, CursorMode.Auto); return; } // If a friendly anthill is the topMostSelectable and we currently have a Gatherer with food selected, tell it to drop food off if (selectedObject.GetComponent<GathererUnit>() != null && selectedObject.GetComponentInChildren<Food>() != null && hoveredObject.GetComponent<Anthill>() != null && hoveredObject.isNeutralOrFriendly()) { Cursor.SetCursor(dropAtHomeCursor, Vector2.zero, CursorMode.Auto); return; } } } // Lastly, if no cursor has been set, use the default setDefaultCursor(); }