Hi folks
I am trying to implement a hotbar for my player inventory (game is played on controller) thus they use RB/LB to navigate the hotbar, but I want the highlighter to skip to the next spot with an item, ignoring empty spots. I am pretty sure Minecraft works this way, so you have an idea of what I’m trying to do.
Anyway, I have written the following block of code that is called in my Input function that is called in Update, so this is happening every frame. I am afraid that this is an inefficient way to handle this, but I can’t think of a better way to do this.
My code below appears to work fine but I fear checking this every frame is bad
If anyone has any insight or ideas it would be much appreciated!
if (rightBumperBool)
{
for (int i = inventoryIndexer; i < gunInventory.Length-1; i++)
{
if (gunInventory[i + 1] != null)
{
inventoryIndexer = i + 1;
break;
}
}
}
if (leftBumperBool)
{
for (int i = inventoryIndexer; i > 0; i --)
{
if (gunInventory[i - 1] != null)
{
inventoryIndexer = i - 1;
break;
}
}
}