I Have A Project Space Shooter Which Shoots Continuously on Aliens ,I Want It To Shoot While Pressing Button,Help Me

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Dheepanraj

script: ship

extends Area2D

var armor = 4 setget set_armor
const scn_laser = preload(“res://scenes/laser_ship.tscn”)
const scn_explosion = preload(“res://scenes/explosion.tscn”)
const scn_flash = preload(“res://scenes/flash.tscn”)

signal armor_changed

func _ready():
set_process(true)
add_to_group(“ship”)

yield(utils.create_timer(0.5), "timeout")
	

	

	
shoot()
	
pass

func _process(delta):
# tracking mouse
var motion = (utils.mouse_pos.x - get_pos().x) * 0.2
translate(Vector2(motion, 0))

# clamping to view
var pos = get_pos()
pos.x   = clamp(pos.x, 0+16, utils.view_size.width-16)
set_pos(pos)


pass

func shoot():
while true:

	var pos_left  = get_node("cannons/left" ).get_global_pos()
	var pos_right = get_node("cannons/right").get_global_pos()
	create_laser(pos_left )
	create_laser(pos_right)
	
	yield(utils.create_timer(0.25), "timeout")
pass

func set_armor(new_value):
if new_value < armor:
utils.main_node.add_child(scn_flash.instance())

armor = new_value
emit_signal("armor_changed", armor)

if armor <= 0:
	create_explosion()
	queue_free()
pass

func create_laser(pos):
var laser = scn_laser.instance()
laser.set_pos(pos)
utils.main_node.add_child(laser)
pass

func create_explosion():
var explosion = scn_explosion.instance()
explosion.set_pos(get_pos())
utils.main_node.add_child(explosion)
pass

:bust_in_silhouette: Reply From: payload505

Don’t panic Iam really new to godot but i suppose this is easy just try to put your shooting function inside a pressed button

Thank You Your Comment Was Helpful

Dheepanraj | 2020-03-23 13:31

:bust_in_silhouette: Reply From: potatobanana

this play list teach us how to make simple space shoot game.

try use input function or use

func _input(event: InputEvent) -> void:
	pass

something like :

if Input.is_action_pressed("Lclick") : # if you use Input.is_action_pressed it keep shoot until you release press, if you use Input.is_action_just_pressed it will shot once each click.
shoot() #shoot function

Thank You Your Comment Was Helpful .But I am Facing An Issue It Is Not Working I Hope it is Because the older version 2.1.6. When I Use the Input Function It Gets Stopped

Dheepanraj | 2020-03-23 13:38

i hope so, i use 3.2

potatobanana | 2020-03-23 16:30