Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | malkav182 |
I have this function that should emit a signal, but my signal does not seem to be working as I expected. It does everything inside that function hit_bottom()…
extends Area2D
signal recharge
func _ready():
pass # Replace with function body.
func hit_bottom(node):
$"../../shoot".position = node.position
node.queue_free()
emit_signal("recharge")
pass
… but the other script does not run the function associated with that signal emitted.
extends KinematicBody2D
var ball = preload("res://scenes/ball.tscn")
var velocity = Vector2()
export (int) var cartridge = 50
var initial_pos = Vector2()
var wait = true
func _ready():
self.connect("recharge" , self , "on_recharge")
func get_input():
velocity = Vector2()
if Input.is_action_just_pressed("ui_shoot"):
wait = false
initial_pos = get_global_mouse_position() - $muzzle.global_position
shoot()
func shoot():
if cartridge > 0:
var b = ball.instance()
b.add_to_group("balls")
var g = get_tree().get_nodes_in_group("balls")
var dir = initial_pos
if dir.length() > 5:
rotation = dir.angle()
velocity = move_and_slide(velocity)
b.start($muzzle.global_position , rotation)
get_parent().add_child(b)
cartridge -= 1
$interval.start()
print(cartridge)
func _physics_process(delta):
get_input()
func _on_interval_timeout():
shoot()
func on_recharge():
cartridge += 1
print("Cartridge: " , cartridge)
This second script is from a different scene that is instanced in the scene from the first code. How can I connect them?