Hello, I have an inventory in my game and when the player plays with controller, it switches to the controller input.
Well with the keyboard, it is simple. the player can select which slot he want to hold by pressing the number pad 1 till 4 (I have only 4 slots)
But with the ps4 controller, I stuck with the problem since I want the slot switch to the next slot with the R1 button and to switch to the previous one, you have to press the L1.
If you press R1 while you hold the 4th slot, it needs to switch back to slot 1.
I really need help with this one.
Can someone help me out with this one?
This is what I got so far…
public List<SlotsSelector> slotsSelectors;
public EquipArea equipArea;
public Inventory inventory;
public delegate void OnSelectSlot(int indexOfSlot);
public event OnSelectSlot onSelectSlot;
void Start()
{
inventory = GetComponentInParent<Inventory>();
for (int i = 0; i < slotsSelectors.Count; i++)
{
onSelectSlot += slotsSelectors*.Select;*
}
onSelectSlot?.Invoke(0);
}
void Update()
{
if (!inventory || !equipArea || inventory.lockInventoryInput) return;
for (int i = 0; i < slotsSelectors.Count; i++)
{
if (Input.GetButtonDown(“PS4_R1”) && slotsSelectors_.indexOfSlot >= 0 && slotsSelectors*.indexOfSlot <= 2 && (inventory && !inventory.IsLocked() && !inventory.isOpen && inventory.canEquip))
{_
_slotsSelectors.indexOfSlot ++;
}*_
if (Input.GetButtonDown(“PS4_L1”) && (inventory && !inventory.IsLocked() && !inventory.isOpen && inventory.canEquip))
{
if (slotsSelectors_.indexOfSlot < equipArea.equipSlots.Count && slotsSelectors*.indexOfSlot >= 0)
{_
_equipArea.SetEquipSlot(slotsSelectors.indexOfSlot);_
_onSelectSlot?.Invoke(slotsSelectors.indexOfSlot);
}
}*_
if (slotsSelectors.equipDisplay != null && slotsSelectors_.indexOfSlot < equipArea.equipSlots.Count && slotsSelectors*.indexOfSlot >= 0)
{
if (equipArea.equipSlots[slotsSelectors.indexOfSlot].item != slotsSelectors.equipDisplay.item)
{
slotsSelectors.equipDisplay.AddItem(equipArea.equipSlots[slotsSelectors.indexOfSlot].item);
}
else if (equipArea.equipSlots[slotsSelectors.indexOfSlot].item == null && slotsSelectors.equipDisplay.hasItem)
{_
_slotsSelectors.equipDisplay.RemoveItem();
}
}
}
}*_
[System.Serializable]
public class SlotsSelector
{
public int indexOfSlot;
public EquipmentDisplay equipDisplay;
public bool selected;
public void Select(int indexOfSlot)
{
if (this.indexOfSlot != indexOfSlot && selected)
{
equipDisplay.onDeselect.Invoke();
selected = false;
}
else if (this.indexOfSlot == indexOfSlot && !selected)
{
equipDisplay.onSelect.Invoke();
selected = true;
}
}
}
I’m really dizzy right now, just trying to figure this out.