mirror of
https://github.com/DerTyp7/example-top-down-unity.git
synced 2025-10-29 12:32:09 +01:00
43 lines
968 B
C#
43 lines
968 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class InventoryController : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
int selectedSlotIndex;
|
|
|
|
Inventory inventory;
|
|
|
|
public static InventoryController PlayerInstance { get; private set; }
|
|
|
|
public Slot GetSelectedSlot()
|
|
{
|
|
return inventory.GetInventory()[selectedSlotIndex];
|
|
}
|
|
void Start()
|
|
{
|
|
PlayerInstance = this;
|
|
inventory = Inventory.PlayerInstance;
|
|
selectedSlotIndex = 0;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (Input.GetAxis("Mouse ScrollWheel") < 0)
|
|
{
|
|
if (inventory.IndexIsInRange(selectedSlotIndex - 1))
|
|
{
|
|
selectedSlotIndex -= 1;
|
|
}
|
|
}
|
|
if (Input.GetAxis("Mouse ScrollWheel") > 0)
|
|
{
|
|
if (inventory.IndexIsInRange(selectedSlotIndex + 1))
|
|
{
|
|
selectedSlotIndex += 1;
|
|
}
|
|
}
|
|
}
|
|
}
|