This is an old revision of the document!
export var fire_rate = 0.5 export var clip_size = 5 export var reload_rate = 1 var current_ammo = clip_size var can_fire = true func _process(delta): if Input.is_action_just_pressed("primary_fire") and can_fire: print "Fired weapon"
func _process(delta): if Input.is_action_just_pressed("primary_fire") and can_fire: print "Fired weapon" can_fire = false yield(get_tree().create_timer(fire_rate), "timeout") can_fire = true
func _process(delta): if Input.is_action_just_pressed("primary_fire") and can_fire: if current_ammo > 0: print "Fired weapon" can_fire = false current_ammo -= 1 yield(get_tree().create_timer(fire_rate), "timeout") can_fire = true else: print "Reloading" yield(get_tree().create_timer(reload_rate), "timeout") current_ammo = clip_size print "Reload complete"
export var fire_rate = 0.5 export var clip_size = 5 export var reload_rate = 1 var current_ammo = clip_size var can_fire = true var reloading = false func _process(delta): if Input.is_action_just_pressed("primary_fire") and can_fire: if current_ammo > 0 and not reloading: print "Fired weapon" can_fire = false current_ammo -= 1 elif not reloading: print "Reloading" reloading = true yield(get_tree().create_timer(reload_rate), "timeout") current_ammo = clip_size reloading = false print "Reload complete"