0 votes

Hi, I have two function one it reload and another it shoot but thing is I do not know how I can set my reload function false when the player do the function shoot. I try few thing but it did not work and I am stuck whit a player can soot and reload at the same time
here the code:


func shoot():
if ammo !=0:
        emit_signal("ammo_changed",ammo *150/max_ammo)

        can_shoot = false

        var pew = pewSCN.instance()

        pew.position =$Player/Position2D.global_position
        pew.rotation = $Player/Position2D.global_rotation

function reload:

func reload_true():

and my Input use this two function:

func _physics_process(delta):
if Input.is_action_just_pressed("reload"):
    reload_true()#set the shoot function false
    emit_signal("ammo_changed",ammo *150/max_ammo)
if (Input.is_action_just_pressed("shoot")&&can_shoot):
    shoot()#set the reload function false

Thank for helping me :)

in Engine by (77 points)

1 Answer

0 votes

In _physics_process, replace the second if with elif. elifis a combination of the operators if and else. Because of this, if the first if is false, then it will check if the player is pressing the shoot button. However, if the first if is true, then it won't check at all.

by (38 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.