#How to make a weapon switching system?
1 messages · Page 1 of 1 (latest)
You could use an enum, dictionary, and var cur_weapon to make this. (At least, that's what I would do.)
enum WeaponSlots {FIRE_SWORD, ICE_SWORD, ELECTRIC_SWORD} var slots_unlocked = { WeaponSlots.FIRE_SWORD: true, WeaponSlots.ICE_SWORD: false, WeaponSlots.ELECTRIC_SWORD: false, } var cur_weapon = WeaponSlots.FIRE_SWORD
You can get the next/previous weapon using clamp()
`func switch_to_next_weapon():
cur_slot = clamp(cur_slot + 1, 0, slots_unlocked.size())
if !slots_unlocked[cur_slot]:
switch_to_next_weapon()
else:
switch_to_weapon_slot(cur_slot)
func switch_to_last_weapon():
cur_slot = clamp(cur_slot - 1, 0, slots_unlocked.size())
if !slots_unlocked[cur_slot]:
switch_to_last_weapon()
else:
switch_to_weapon_slot(cur_slot)`
You can put the logic to show a different weapon graphic or whatever you want to do in switch_to_weapon_slot(_new_slot) etc
On attack and special attack inputs you can check cur_slot == WeaponSlots.FIRE_SWORD or the other weapons and handle the logic as needed
You can use an Area to detect the player being near the table and popping up the UI. Only allow the player's weapon switching to run when they're near the table
something like that.