I have this Input code to change weapon:
if (d_left)
{
if (!p_d_left)
{
states.inventoryManager.ChangeWeaponToNextWeapon(true);
p_d_left = true;
}
}
if (d_right)
{
if (!p_d_right)
{
states.inventoryManager.ChangeWeaponToNextWeapon(false);
p_d_right = true;
}
And in the InventoryManager I have the weapon changed by this:
public void ChangeWeaponToNextWeapon(bool isLeft)
{
if (isLeft)
{
if (l_index < r_l_weapons.Count - 1)
l_index++;
else
l_index = 0;
EquipWeapon(r_l_weapons[l_index], true);
}
else
{
if (r_index < r_r_weapons.Count - 1)
r_index++;
else
r_index = 0;
EquipWeapon(r_r_weapons[r_index]);
}
states.actionManager.UpdateActionsOneHanded();
}
Then equip the weapon along with animation and other stuff :
public void EquipWeapon(RuntimeWeapon w, bool isLeft = false)
{
if (isLeft)
{
if (leftHandWeapon != null)
{
leftHandWeapon.weaponModel.SetActive(false);
}
leftHandWeapon = w;
}
else
{
if (rightHandWeapon != null)
{
rightHandWeapon.weaponModel.SetActive(false);
}
rightHandWeapon = w;
}
string targetIdle = w.instance.oh_idle;
targetIdle += (isLeft) ? "_l" : "_r";
states.anim.SetBool(StaticStrings.mirror, isLeft);
states.anim.Play(StaticStrings.changeWeapon);
states.anim.Play(targetIdle);
UI.Slot uiSlot = UI.Slot.singleton;
uiSlot.UpdateSlot(
(isLeft) ?
UI.QSlotType.lh : UI.QSlotType.rh, w.instance.icon);
w.weaponModel.SetActive(true);
}
But the problem is the weapon changes immediately after pressing the button. How can I switch my weapon a few frames later while playing the animation?