Okay, so I have code for switching weapons but, I don’t know how to integrate it with code that would make the player pick up weapons (Doom-Style). The player is already holding all the guns, while all weapon switching really does is control which gun is visible and functioning. Just like the weapon switching code, I only want to create the illusion of picking up weapons as oppose to actually picking up anything. The goal would be to have a (preferably Boolean) variable in each weapon that represents whether or not the weapon has been picked up, and then have the weapon switching code deliberately skip weapons that haven’t been picked up. All the weapon pick ups would actually do is toggle the variable in the weapons that determined which weapon is picked up. Now even though I know what I want in theory, I have a hard time implementing it in practice. I’ve tried while loops, only for that to cause my game to crash. Does anyone have any idea how I can impliment the weapon pick up machanic I want?
Here is the code for my weapon switching:
if event is InputEventMouseButton:#Without this line of code(if event is InputEventMouseButton), mouse buttons buttons wouldn't work.
if Input.is_action_just_pressed("mouse_wheel_up") and not equip:#Input for scrolling the mouse wheel up.
change_weapon(wrapi(weapon_index + 1,0,max_weapon+1))
elif Input.is_action_just_pressed("mouse_wheel_down") and not equip:#Input for scrolling the mouse wheel down.
change_weapon(wrapi(weapon_index - 1,0,max_weapon+1))
current_weapon = inventory[weapon_index]
if Input.is_action_just_pressed("weapon1") and weapon_index != 0 and not equip:
elif Input.is_action_just_pressed("weapon2") and weapon_index != 1 and not equip:
elif Input.is_action_just_pressed("weapon3") and weapon_index != 2 and not equip:
elif Input.is_action_just_pressed("weapon4") and weapon_index != 3 and not equip:
for i in inventory:
if i == current_weapon:
if equip == false:
func equip_anim(anim):#Function for equip/enquip animation
anim_player.playback_speed = 2;anim
if my_weapon_index <= max_weapon:#This helps to change weapons!
equip = true;equip_anim(anim_player.play_backwards(equip_anim[weapon_index]))
weapon_index = my_weapon_index
yield(anim_player,"animation_finished");equip = false
Do you know how you would integrate weapon picks ups into this code?