Question by
ibouchallikht · Dec 19, 2020 at 04:28 AM ·
keyselectslotnext
Select next slot with keybutton
Hi all,
I got stuck with a issue.
For my game, I want to make my game work properly on a ps4 controller.
I have 4 slots for the player to carry weapons or items.
What I try to do is, whenever the player presses the "PS4_R1" button, it should select the next slot and with the "PS4_L1" button the previous one.
When the last slot is selected and the player presses "PS4_R1" again, it should select the first slot again and vice versa for the "PS4_L1" button.
I hope you guys understand my issue and hope someone can help me out.
My thanks is great!!
public class ControlAreaByInputNew : vMonoBehaviour
{
public List<SlotsSelector> slotsSelectors;
public vEquipArea equipArea;
public vInventory inventory;
public delegate void OnSelectSlot(int indexOfSlot);
public event OnSelectSlot onSelectSlot;
void Start()
{
inventory = GetComponentInParent<vInventory>();
for (int i = 0; i < slotsSelectors.Count; i++)
{
onSelectSlot += slotsSelectors[i].Select;
}
onSelectSlot?.Invoke(0);
}
void Update()
{
if (!inventory || !equipArea || inventory.lockInventoryInput) return;
for (int i = 0; i < slotsSelectors.Count; i++)
{
if (slotsSelectors[i].input.GetButtonDown() && (inventory && !inventory.IsLocked() && !inventory.isOpen && inventory.canEquip))
{
if (slotsSelectors[i].indexOfSlot < equipArea.equipSlots.Count && slotsSelectors[i].indexOfSlot >= 0)
{
equipArea.SetEquipSlot(slotsSelectors[i].indexOfSlot);
onSelectSlot?.Invoke(slotsSelectors[i].indexOfSlot);
}
}
if (slotsSelectors[i].equipDisplay != null && slotsSelectors[i].indexOfSlot < equipArea.equipSlots.Count && slotsSelectors[i].indexOfSlot >= 0)
{
if (equipArea.equipSlots[slotsSelectors[i].indexOfSlot].item != slotsSelectors[i].equipDisplay.item)
{
slotsSelectors[i].equipDisplay.AddItem(equipArea.equipSlots[slotsSelectors[i].indexOfSlot].item);
}
else if (equipArea.equipSlots[slotsSelectors[i].indexOfSlot].item == null && slotsSelectors[i].equipDisplay.hasItem)
{
slotsSelectors[i].equipDisplay.RemoveItem();
}
}
}
}
Comment
Your answer
