Archived
Private
Public Access
1
0
This repository has been archived on 2026-02-04. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
ProjectBackup/Unity/Minecraft/Assets/Scripts/UI/Toolbar.cs
2022-11-12 13:10:03 +01:00

37 lines
1006 B
C#

using Items;
using UnityEngine;
using Random = UnityEngine.Random;
namespace UI {
public class Toolbar : MonoBehaviour {
public UIItemSlot[] slots;
public RectTransform highlight;
public int slotIndex;
private void Start() {
for (var i = 0; i < slots.Length; i++) {
ItemStack stack = new ItemStack((byte)(i + 1), Random.Range(2, 50));
new ItemSlot(slots[i], stack);
}
}
private void Update() {
float scroll = Input.GetAxis("Mouse ScrollWheel");
if (scroll != 0) {
if (scroll > 0)
slotIndex--;
else
slotIndex++;
if (slotIndex >= slots.Length)
slotIndex = 0;
if (slotIndex < 0)
slotIndex = slots.Length - 1;
highlight.position = slots[slotIndex].slotIcon.transform.position;
}
}
}
}