Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | System_Error |
Hi all. I’m nearly done with the code for a game I’ve been making this past week. Just a few more things to do before I get to spriting, and levels.
I’ve a Signal called ‘game_over’, and I’d like to disable the code that listens for Input when the signal fires. The below code is from LazerGun.gd.
extends KinematicBody2D
const LAZER = preload("res://player-side/EnergyShot.tscn")
const ROTATION_SPEED = 0.5
signal fire
var rotation_Direction
func _ready():
pass
func get_input():
rotation_Direction = 0.0
if Input.is_action_pressed('test_up'):
rotation_Direction -= 1.0
elif Input.is_action_pressed('test_down'):
rotation_Direction += 1.0
if Input.is_action_just_pressed('test_fire'):
fire()
func fire():
var lazershot = LAZER.instance()
lazershot.start($LazerSpawn.global_position, rotation)
get_parent().add_child(lazershot)
func _physics_process(delta):
get_input()
rotation += rotation_Direction * ROTATION_SPEED * delta
rotation = clamp(rotation, deg2rad(-45), deg2rad(45))
func _on_game_over():
pass # replace with function body
Again, I’d like to disable the ‘get_input()’ function when ‘game_over’ fires. I can figure out how to get the gun working after a game over.
the more obvious answer is just
var playing = true
func _on_game_over():
playing = false
func _physics_process():
if playing:
get_input()
but im not posting it as answer because there may be a better way of doing it
RazorSh4rk | 2018-12-15 20:08
Thanks, RazorSh4rk. This works.
System_Error | 2018-12-15 21:55
Could you post as an answer so others can se its solved?
p7f | 2018-12-16 14:57