Ever wanted to create a game like Harvest Moon in Unity? Check out Part 33 of our guide here, where we fix a bug with chicken hatching, and add new features to our inventory system. You can also find Part 32 of our guide here, where we created our weather system.
1. Bug Fixes
a. Fixing the Regrowable Harvestable Bug
Some viewers reported on the forums that when harvesting tomatoes, items already in their hands were getting overwritten.
To fix this, we need to add a check to our Pickup() function in the RegrowableHarvestBehaviour script.
using System.Collections;More actions
using System.Collections.Generic;
using UnityEngine;
public class RegrowableHarvestBehaviour : InteractableObject
{
CropBehaviour parentCrop;
//Sets the parent crop
public void SetParent(CropBehaviour parentCrop)
{
this.parentCrop = parentCrop;
}
public override void Pickup()
{
//Do an additional check to see if it can be harvested
if(parentCrop.cropState != CropBehaviour.CropState.Harvestable)
{
UIManager.Instance.DeactivateInteractPrompt();
return;
}
//Call the OnInteract Callback
onInteract?.Invoke();
//Check if the player is holding on to an item
if (InventoryManager.Instance.SlotEquipped(InventorySlot.InventoryType.Item))
{
//Send the item to inventory before equipping
InventoryManager.Instance.HandToInventory(InventorySlot.InventoryType.Item);
}
//Set the player's inventory to the item
InventoryManager.Instance.EquipHandSlot(item);
//Update the changes in the scene
InventoryManager.Instance.RenderHand();
//Set the parent crop back to seedling to regrow it
parentCrop.Regrow();
UIManager.Instance.DeactivateInteractPrompt();
}
}
b. Fixing Race Condition Bug with Animal Spawning
It was also reported that when hatching multiple eggs simultaneously, only one chick would remain after saving and reloading the game.
The issue is that when multiple eggs hatched at the same time, the code was accessing and modifying shared data on the blackboard at the same time. We are retrieving the animal count and type count before the player named their animal.
To fix this, we will move our blackboard operations inside the naming prompt callback. This naturally prevents the race condition. Each animal creation now completes fully before the next one begins, ensuring all animals are properly saved.
using System.Collections;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
public class AnimalStats : MonoBehaviour
{
public const string ANIMAL_COUNT = "AnimalCount";
public const string ANIMAL_DATA = "AnimalRelationship";
//The relationship data of all the NPCs that the player has met in the game
public static List<AnimalRelationshipState> animalRelationships = new List<AnimalRelationshipState>();
//Load all the animal data scriptable objects
static List<AnimalData> animals = Resources.LoadAll<AnimalData>("Animals").ToList();
//To be fired up when a new animal is born or purchased
public static void StartAnimalCreation(AnimalData animalType)
{//Retrieve Blackboard
GameBlackboard blackboard = GameStateManager.Instance.GetBlackboard();
//Initialise animal count parameter
if (!blackboard.TryGetValue(ANIMAL_COUNT, out int animalCount))
{
blackboard.SetValue(ANIMAL_COUNT, 0);
animalCount = 0;
}
//Handle stats on animal type
if (!blackboard.TryGetValue(ANIMAL_COUNT + animalType.name, out int animalTypeCount))
{
blackboard.SetValue(ANIMAL_COUNT + animalType.name, 0);
animalTypeCount = 0;
}
//Handle Animal spawning here
UIManager.Instance.TriggerNamingPrompt($"Give your new {animalType.name} a name.", (inputString) => {
//Retrieve Blackboard
GameBlackboard blackboard = GameStateManager.Instance.GetBlackboard();
//Initialise animal count parameter
if (!blackboard.TryGetValue(ANIMAL_COUNT, out int animalCount))
{
blackboard.SetValue(ANIMAL_COUNT, 0);
animalCount = 0;
}
//Handle stats on animal type
if (!blackboard.TryGetValue(ANIMAL_COUNT + animalType.name, out int animalTypeCount))
{
blackboard.SetValue(ANIMAL_COUNT + animalType.name, 0);
animalTypeCount = 0;
}
//Create a new animal and add it to the animal relationships data
AnimalRelationshipState animalRelationshipData = new AnimalRelationshipState(animalCount, inputString, animalType);
//Save the entry of the relationship to the blackboard
//Animal entries are set by number, e.g. if this is the first animal it will be of id 0
blackboard.SetValue(ANIMAL_DATA + animalCount, animalRelationshipData);
//Statistics update
animalCount++;
animalTypeCount++;
blackboard.SetValue(ANIMAL_COUNT, animalCount);
blackboard.SetValue(ANIMAL_COUNT + animalType.name, animalTypeCount);
//Add it to our local cache
animalRelationships.Add(animalRelationshipData);
});
}
//Load in the animal relationships
public static void LoadStats()
{
//Load from the Blackboard data
animalRelationships = new List<AnimalRelationshipState>();
GameBlackboard blackboard = GameStateManager.Instance.GetBlackboard();
//Get the animal count
if(blackboard.TryGetValue(ANIMAL_COUNT, out int animalCount)){
for (int i = 0; i < animalCount; i++)
{
if (!blackboard.TryGetValue(ANIMAL_DATA + i, out AnimalRelationshipState animalRelationship)) continue;
animalRelationships.Add(animalRelationship);
}
}
/*
Debug.Log("Animals: " + relationshipsToLoad.Count);
if(relationshipsToLoad == null)
{
animalRelationships = new List<AnimalRelationshipState>();
return;
}
animalRelationships = relationshipsToLoad;
*/
}
//Get the animals by type
public static List<AnimalRelationshipState> GetAnimalsByType(string animalTypeName)
{
return animalRelationships.FindAll(x => x.animalType == animalTypeName);
}
public static List<AnimalRelationshipState> GetAnimalsByType(AnimalData animalType)
{
return GetAnimalsByType(animalType.name);
}
public static void OnDayReset()
{
GameBlackboard blackboard = GameStateManager.Instance.GetBlackboard();
//Reset animal relationship states
foreach (AnimalRelationshipState animal in AnimalStats.animalRelationships)
{
//Increase friendship if player has spoken with the animal
if (animal.hasTalkedToday)
{
animal.friendshipPoints += 30;
} else
{
animal.friendshipPoints -= (10 - (animal.friendshipPoints / 200));
}
//Feeding
if (animal.giftGivenToday)
{
animal.Mood += 15;
}
else
{
animal.Mood -= 100;
animal.friendshipPoints -= 20;
}
animal.hasTalkedToday = false;
//Gift given refers to whether the animal has been fed
animal.giftGivenToday = false;
animal.givenProduceToday = false;
//Advance the age of the animal
animal.age++;
//Update its value in the blackboard
blackboard.SetValue(ANIMAL_DATA + animal.id, animal);
}
}
//Get the animal data type from a string
public static AnimalData GetAnimalTypeFromString(string name)
{
return animals.Find(i => i.name == name);
}
}
2. Minecraft-like Inventory System
Next, we will improve our inventory system and make moving items around feel much more intuitive. We will have our inventory system work similar to Minecraft, where different mouse clicks are handled with different actions depending on the context.

a. Inventory script setup
First, we'll make a few changes to InventorySlot script. We will change slotIndex variable to be protected so it can be accessed by HandInventorySlot later. We will also modify our OnPointerClick method to detect shift and right click inputs.
using System.Collections;More actions
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using TMPro;
public class InventorySlot : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
{
ItemData itemToDisplay;
int quantity;
public Image itemDisplayImage;
public TextMeshProUGUI quantityText;
public enum InventoryType
{
Item, Tool
}
//Determines which inventory section this slot is apart of.
public InventoryType inventoryType;int slotIndex;
protected int slotIndex;
public void Display(ItemSlotData itemSlot)
{
//Set the variables accordingly
itemToDisplay = itemSlot.itemData;
quantity = itemSlot.quantity;
//By default, the quantity text should not show
quantityText.text = "";
//Check if there is an item to display
if(itemToDisplay != null)
{
//Switch the thumbnail over
itemDisplayImage.sprite = itemToDisplay.thumbnail;
//Display the stack quantity if there is more than 1 in the stack
if(quantity > 1)
{
quantityText.text = quantity.ToString();
}
itemDisplayImage.gameObject.SetActive(true);
return;
}
itemDisplayImage.gameObject.SetActive(false);
}
public virtual void OnPointerClick(PointerEventData eventData)
{
//Check if it is a right or left click
bool isRightClick = (eventData.button == PointerEventData.InputButton.Right);
bool shift = Input.GetKey(KeyCode.LeftShift);
if (!isRightClick && shift)
{
MoveEntireStack();
} else
{
InventoryManager.Instance.SelectSlot(slotIndex, inventoryType, isRightClick);
}
}
/// <summary>
/// Handles the movement of items by the entire stack. Triggered when the player holds left shift + left click
/// </summary>
protected virtual void MoveEntireStack()
{
//Move item from inventory to hand
InventoryManager.Instance.InventoryToHand(slotIndex, inventoryType);
}
//Set the Slot index
public void AssignIndex(int slotIndex)
{
this.slotIndex = slotIndex;
}
//Display the item info on the item info box when the player mouses over
public void OnPointerEnter(PointerEventData eventData)
{
UIManager.Instance.DisplayItemInfo(itemToDisplay);
}
//Reset the item info box when the player leaves
public void OnPointerExit(PointerEventData eventData)
{
UIManager.Instance.DisplayItemInfo(null);
}
}
b. Updating supporting scripts
Next for our HandInventorySlot.cs
, We added an Awake
method and set the slot index to -1. This is our special identifier for the hand slot. We also refactored its click handling by moving the functionality to a new MoveEntireStack
method.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class HandInventorySlot : InventorySlot
{public override void OnPointerClick(PointerEventData eventData)
private void Awake()
{
//Hand slot is always -1
slotIndex = -1;
}
protected override void MoveEntireStack()
{
//Move item from hand to inventory
InventoryManager.Instance.HandToInventory(inventoryType);
}
}
We then add new variables to the InventoryManager
to track the currently selected item and its original position. After that, we can implement the SelectSlot
method which handles all possible interaction cases.
We will also need to implement some helper methods that handles moving items between slots, retrieving slot data, and swapping items.
SlotToSelection
: Moves items from a slot to the selection; can transfer a full stack or a specific quantity.
SelectionToSlot
: Places the selected item into a slot or hand, then clears the selection.
GetSlotData
: Returns item data from any slot, including the hand (-1 index), for consistent access.
SwapSelection
: Swaps the selected item with the contents of a target slot.
... Other Code ...
public Transform handPoint;
//Inventory Selection System
ItemSlotData selectedItemSlot = new ItemSlotData(null, 0);
int originalIndex = -2;
//Load the inventory from a save
public void LoadInventory(ItemSlotData[] toolSlots, ItemSlotData equippedToolSlot, ItemSlotData[] itemSlots, ItemSlotData equippedItemSlot)
{
this.toolSlots = toolSlots;
this.equippedToolSlot = equippedToolSlot;
this.itemSlots = itemSlots;
this.equippedItemSlot = equippedItemSlot;
//Update the changes in the UI and scene
UIManager.Instance.RenderInventory();
RenderHand();
}
/// <summary>
/// Handles the Selection of the Slot
/// </summary>
/// <param name="slotIndex">The index of the slot</param>
/// <param name="inventoryType">The inventory type</param>
/// <param name="isRightClick">Whether it is a right click</param>
public void SelectSlot(int slotIndex, InventorySlot.InventoryType inventoryType, bool isRightClick)
{
bool hasSelection = !selectedItemSlot.IsEmpty();
//Get the slot in question
ItemSlotData slotToManipulate = GetSlotData(slotIndex, inventoryType);
//Now that we have the slot in question, see if the slot is empty
bool slotHasSomething = !slotToManipulate.IsEmpty();
//Variables in play:
//selection: Whether we have anything selected
//slotIsEmpty: Whether the slot we've selected is empty
//Case 0: No selection, slot has nothing. Nothing to do here
if (!hasSelection && !slotHasSomething) return;
//Check if selection matches slots
if (hasSelection)
{
if (IsTool(selectedItemSlot.itemData) && inventoryType != InventorySlot.InventoryType.Tool) return;
if (!IsTool(selectedItemSlot.itemData) && inventoryType != InventorySlot.InventoryType.Item) return;
}
//Case 1: No selection, slot filled with something
if (!hasSelection && slotHasSomething)
{
Debug.Log("Selection Case 1");
//Left Click
if (!isRightClick)
{
SlotToSelection(slotIndex, inventoryType);
} else
{
//Right Click
//Check if the quantity is 1
if(selectedItemSlot.quantity == 1)
{
SlotToSelection(slotIndex, inventoryType);
} else
{
//Select half the slots
int quantityToTake = slotToManipulate.quantity / 2;
Debug.Log("Taking " + quantityToTake);
SlotToSelection(slotIndex, inventoryType, quantityToTake);
}
}
//Render the inventory
UIManager.Instance.RenderInventory();
return;
}
//Case 2: Selection has something, slot has nothing
if(hasSelection && !slotHasSomething)
{
Debug.Log("Selection Case 2");
//Left Click
if (!isRightClick)
{
SelectionToSlot(slotIndex, inventoryType);
}
else
{
//Right Click
//If exactly 1, just transfer the whole thing
if(slotToManipulate.quantity == 1)
{
SelectionToSlot(slotIndex, inventoryType);
} else
{
//Add 1 of the selection into the slot
selectedItemSlot.Remove();
//Cache this remaining value
ItemSlotData newSelectionValue = new ItemSlotData(selectedItemSlot);
//Transfer exactly 1 to the inventory slot
selectedItemSlot.quantity = 1;
SelectionToSlot(slotIndex, inventoryType);
//Put back the selection
selectedItemSlot = newSelectionValue;
}
}
//Render the inventory
UIManager.Instance.RenderInventory();
return;
}
//Case 3: Selection has something, slot has something
if(hasSelection && slotHasSomething)
{
Debug.Log("Selection Case 3");
//Left Click
if (!isRightClick)
{
//Can they stack?
if (selectedItemSlot.Stackable(slotToManipulate))
{
//If yes, stack
slotToManipulate.AddQuantity(selectedItemSlot.quantity);
selectedItemSlot.Empty();
}
else
{
//If no, don't stack and just swap selection with item
SwapSelection(slotIndex, inventoryType);
}
}
else
{
//Right Click
//Can they stack?
if (selectedItemSlot.Stackable(slotToManipulate))
{
//If yes, stack 1
//Add 1 of the selection into the slot
selectedItemSlot.Remove();
slotToManipulate.AddQuantity(1);
}
else
{
//If no, don't stack and just swap selection with item
SwapSelection(slotIndex, inventoryType);
}
}
//Render the inventory
UIManager.Instance.RenderInventory();
return;
}
}
/// <summary>
/// Handle moving slot data to the selection
/// </summary>
/// <param name="slotIndex"></param>
/// <param name="inventoryType"></param>
/// <param name="quantity">The amount to transfer. -1 for all</param>
void SlotToSelection(int slotIndex, InventorySlot.InventoryType inventoryType, int quantity=-1)
{
ItemSlotData slotToManipulate = GetSlotData(slotIndex, inventoryType);
//Set the quantity accordingly
if (quantity == -1) quantity = slotToManipulate.quantity;
selectedItemSlot = new ItemSlotData(slotToManipulate.itemData, quantity);
switch(inventoryType)
{
case InventorySlot.InventoryType.Item:
if (slotIndex == -1)
{
equippedItemSlot.AddQuantity(-quantity);
break;
}
itemSlots[slotIndex].AddQuantity(-quantity);
break;
case InventorySlot.InventoryType.Tool:
if (slotIndex == -1)
{
equippedToolSlot.AddQuantity(-quantity);
break;
}
toolSlots[slotIndex].AddQuantity(-quantity);
break;
}
}
void SelectionToSlot(int slotIndex, InventorySlot.InventoryType inventoryType)
{
switch (inventoryType)
{
case InventorySlot.InventoryType.Item:
if (slotIndex == -1)
{
equippedItemSlot = new ItemSlotData(selectedItemSlot);
} else
{
itemSlots[slotIndex] = new ItemSlotData(selectedItemSlot);
}
break;
case InventorySlot.InventoryType.Tool:
if (slotIndex == -1)
{
equippedToolSlot = new ItemSlotData(selectedItemSlot);
}
else
{
toolSlots[slotIndex] = new ItemSlotData(selectedItemSlot);
}
break;
}
originalIndex = -2;
selectedItemSlot.Empty();
}
/// <summary>
/// Get the data Item Slot data of the given slot.
/// </summary>
/// <param name="slotIndex">The index of the slot. -1 for hand (equipped item) slot</param>
/// <param name="inventoryType">The inventory type</param>
/// <returns>The Item Slot associated with the slot index and type</returns>
ItemSlotData GetSlotData(int slotIndex, InventorySlot.InventoryType inventoryType)
{
bool isHandSlot = slotIndex == -1;
//Get the slot in question
ItemSlotData slotToManipulate = null;
if (isHandSlot)
{
slotToManipulate = GetEquippedSlot(inventoryType);
return slotToManipulate;
}
switch (inventoryType)
{
case InventorySlot.InventoryType.Item:
slotToManipulate = itemSlots[slotIndex];
break;
case InventorySlot.InventoryType.Tool:
slotToManipulate = toolSlots[slotIndex];
break;
}
return slotToManipulate;
}
void SwapSelection(int slotIndex, InventorySlot.InventoryType inventoryType)
{
//Cache the selected slot
ItemSlotData selectedSlotCache = new ItemSlotData(selectedItemSlot);
//Retrieve the associated slot data
ItemSlotData slotToManipulate = GetSlotData(slotIndex, inventoryType);
selectedItemSlot = new ItemSlotData(slotToManipulate);
switch (inventoryType)
{
case InventorySlot.InventoryType.Item:
if (slotIndex == -1)
{
equippedItemSlot = selectedSlotCache;
return;
}
itemSlots[slotIndex] = selectedSlotCache;
break;
case InventorySlot.InventoryType.Tool:
if (slotIndex == -1)
{
equippedToolSlot = selectedSlotCache;
return;
}
toolSlots[slotIndex] = selectedSlotCache;
break;
}
}
... Other Code ...
3. Selection display cursor
With our selection logic in place, we now need a visual representation to show what item the player is currently holding.
a. Unity object setup
Firstly, let's make a copy of our Hand Slot game object under the ToolsPanel of the Inventory Panel.

Next, rename it to SelectedItemDisplay and move it out of ToolsPanel and make it a child of our Inventory Panel directly.
Lastly, remove the Image component of the SelectedItemDisplay object.

b. Creating SelectedItemDisplay script
Next, we will create a script called SelectedItemDisplay
that manages an image component that displays the selected item's thumbnail and a text component that shows its quantity if greater than one. The Start()
method initially disables the display, while the Render()
method updates it based on the current selection.
The Update()
method, continuously adjusts the position to follow the mouse cursor. This gives players clear visual feedback about what they're currently holding and where they'll place it.
We've also updated the UIManager
to render this display whenever the inventory updates. This creates a seamless connection between our selection logic and the visual representation that players see on screen.
using UnityEngine;
using UnityEngine.UI;
public class SelectedItemDisplay : MonoBehaviour
{
[SerializeField] Image itemImage;
[SerializeField] TMPro.TextMeshProUGUI quantityText;
[SerializeField] Vector2 offset;
bool hasSelection;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
//Disable the item
Enable(false);
}
void Enable(bool enabled)
{
itemImage.gameObject.SetActive(enabled);
quantityText.gameObject.SetActive(false);
}
public void Render(ItemSlotData itemSlot)
{
if (itemSlot.IsEmpty())
{
Enable(false);
hasSelection = false;
} else
{
hasSelection = true;
Enable(true);
itemImage.sprite = itemSlot.itemData.thumbnail;
//Check if the item slot is more than 1
if(itemSlot.quantity > 1)
{
quantityText.gameObject.SetActive(true);
quantityText.text = itemSlot.quantity.ToString();
}
}
}
// Update is called once per frame
void Update()
{
if (!hasSelection) return;
transform.position = new Vector3(Input.mousePosition.x + offset.x, Input.mousePosition.y + offset.y, Input.mousePosition.z);
}
}
c. Updating UIManager script
In the UIManager
script, add this variable.
[SerializeField] SelectedItemDisplay itemCursor;
Then modify this function to render this display whenever the inventory updates.
public void RenderInventory()
{
itemCursor.Render(InventoryManager.Instance.GetSelected());
//Get the respective slots to process
ItemSlotData[] inventoryToolSlots = InventoryManager.Instance.GetInventorySlots(InventorySlot.InventoryType.Tool);
ItemSlotData[] inventoryItemSlots = InventoryManager.Instance.GetInventorySlots(InventorySlot.InventoryType.Item);
//Render the Tool section
RenderInventoryPanel(inventoryToolSlots, toolSlots);
//Render the Item section
RenderInventoryPanel(inventoryItemSlots, itemSlots);
//Render the equipped slots
toolHandSlot.Display(InventoryManager.Instance.GetEquippedSlot(InventorySlot.InventoryType.Tool));
itemHandSlot.Display(InventoryManager.Instance.GetEquippedSlot(InventorySlot.InventoryType.Item));
//Get Tool Equip from InventoryManagerMore actions
ItemData equippedTool = InventoryManager.Instance.GetEquippedSlotItem(InventorySlot.InventoryType.Tool);
//Text should be empty by default
toolQuantityText.text = "";
//Check if there is an item to display
if (equippedTool != null)
{
//Switch the thumbnail over
toolEquipSlot.sprite = equippedTool.thumbnail;
toolEquipSlot.gameObject.SetActive(true);
//Get quantity
int quantity = InventoryManager.Instance.GetEquippedSlot(InventorySlot.InventoryType.Tool).quantity;
if (quantity > 1)
{
toolQuantityText.text = quantity.ToString();
}
return;
}
Finally, let's add
4. Cancelling item selection
Finally, we need to ensure players don't accidentally lose items when closing their inventory. To accomplish this, we'll added a CancelSelection
method to the InventoryManager
.
This method ensures selected items are returned to their original slots when the inventory closes, preventing item loss. It's triggered by the OnDisable
method in the SelectedItemDisplay
script.
... Other code...
//Cancel the selection
public void CancelSelection()
{
if (selectedItemSlot.IsEmpty()) return;
Debug.Log("CANCELLING SELECTION");
InventorySlot.InventoryType inventoryType = IsTool(selectedItemSlot.itemData) ? InventorySlot.InventoryType.Tool: InventorySlot.InventoryType.Item;
SelectionToSlot(originalIndex, inventoryType);
UIManager.Instance.RenderInventory();
}
public ItemSlotData GetSelected()
{
return selectedItemSlot;
}
/// <summary>
/// Handle moving slot data to the selection
/// </summary>
/// <param name="slotIndex"></param>
/// <param name="inventoryType"></param>
/// <param name="quantity">The amount to transfer. -1 for all</param>
void SlotToSelection(int slotIndex, InventorySlot.InventoryType inventoryType, int quantity=-1)
{
ItemSlotData slotToManipulate = GetSlotData(slotIndex, inventoryType);
//Set the quantity accordingly
if (quantity == -1) quantity = slotToManipulate.quantity;
selectedItemSlot = new ItemSlotData(slotToManipulate.itemData, quantity);
originalIndex = slotIndex;
switch(inventoryType)
{
case InventorySlot.InventoryType.Item:
if (slotIndex == -1)
{
equippedItemSlot.AddQuantity(-quantity);
break;
}
itemSlots[slotIndex].AddQuantity(-quantity);
break;
case InventorySlot.InventoryType.Tool:
if (slotIndex == -1)
{
equippedToolSlot.AddQuantity(-quantity);
break;
}
toolSlots[slotIndex].AddQuantity(-quantity);
break;
}
}
... Other Code...
using UnityEngine;More actions
using UnityEngine.UI;
public class SelectedItemDisplay : MonoBehaviour
{
[SerializeField] Image itemImage;
[SerializeField] TMPro.TextMeshProUGUI quantityText;
[SerializeField] Vector2 offset;
bool hasSelection;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
//Disable the item
Enable(false);
}
void Enable(bool enabled)
{
itemImage.gameObject.SetActive(enabled);
quantityText.gameObject.SetActive(false);
}
public void Render(ItemSlotData itemSlot)
{
if (itemSlot.IsEmpty())
{
Enable(false);
hasSelection = false;
} else
{
hasSelection = true;
Enable(true);
itemImage.sprite = itemSlot.itemData.thumbnail;
//Check if the item slot is more than 1
if(itemSlot.quantity > 1)
{
quantityText.gameObject.SetActive(true);
quantityText.text = itemSlot.quantity.ToString();
}
}
}
// Update is called once per frame
void Update()
{
if (!hasSelection) return;
transform.position = new Vector3(Input.mousePosition.x + offset.x, Input.mousePosition.y + offset.y, Input.mousePosition.z);
}
//Cancel Selection the moment the panel closes
private void OnDisable()
{
InventoryManager.Instance.CancelSelection();
}
}