i tried to make a menu slide to the screen when the button is pressed with each button react to another button. it did work with the code i wrote. but it seems there is another efficient ways to that. or is it the only way to do that?
extends Control
var target : Vector2 = Vector2(0, 720)
var closed : Vector2 = Vector2(0, 720)
var slider_status = false
var target_node
var closed_node
var button_1_status = false
var button_2_status = false
var button_3_status = false
var button_4_status = false
@onready var parent_node = get_node(".")
@onready var upgrade_node = get_node("upgrade")
@onready var generator_node = get_node("generator")
@onready var upgrade_node2 = get_node("upgrade2")
@onready var generator_node2 = get_node("generator2")
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if target_node != null :
if closed_node != null :
if (target_node.position - target).length() < 0.1 :
target_node.position = target_node.position.lerp(target, delta * 30)
closed_node = target_node
target_node = null
print(closed_node.position)
else :
target_node.position = target_node.position.lerp(target, delta * 30)
closed_node.position = closed_node.position.lerp(closed, delta * 30)
else :
if (target_node.position - target).length() < 0.1 :
closed_node = target_node
target_node = null
print(closed_node.position)
else :
target_node.position = target_node.position.lerp(target, delta * 30)
func _on_open_upgrade_pressed() -> void:
target_node = upgrade_node
if button_2_status or button_3_status or button_4_status :
target = Vector2(0,270)
closed = Vector2(0,720)
button_1_status = true
button_2_status = false
button_3_status = false
button_4_status = false
parent_node.move_child(upgrade_node, 1)
elif button_1_status :
closed_node = null
target = Vector2(0, 720)
button_1_status = false
parent_node.move_child(upgrade_node, 1)
elif !button_1_status and closed_node != null :
target = Vector2(0, 270)
closed_node = null
button_1_status = true
parent_node.move_child(upgrade_node, 1)
else :
target = Vector2(0, 270)
closed_node = null
button_1_status = true
parent_node.move_child(upgrade_node, 1)
func _on_open_generator_pressed() -> void:
target_node = generator_node
if button_1_status or button_3_status or button_4_status :
target = Vector2(0,270)
closed = Vector2(0,720)
button_1_status = false
button_2_status = true
button_3_status = false
button_4_status = false
parent_node.move_child(generator_node, 1)
elif button_2_status :
closed_node = null
target = Vector2(0, 720)
button_2_status = false
parent_node.move_child(generator_node, 1)
elif !button_1_status and closed_node != null :
target = Vector2(0, 270)
closed_node = null
button_2_status = true
parent_node.move_child(generator_node, 1)
else :
target = Vector2(0, 270)
closed_node = null
button_2_status = true
parent_node.move_child(generator_node, 1)
func _on_open_upgrade2_pressed() -> void:
target_node = upgrade_node2
if button_2_status or button_3_status or button_1_status :
target = Vector2(0,270)
closed = Vector2(0,720)
button_1_status = false
button_2_status = false
button_3_status = false
button_4_status = true
parent_node.move_child(upgrade_node2, 1)
elif button_4_status :
closed_node = null
target = Vector2(0, 720)
button_4_status = false
parent_node.move_child(upgrade_node2, 1)
elif !button_4_status and closed_node != null :
target = Vector2(0, 270)
closed_node = null
button_4_status = true
parent_node.move_child(upgrade_node2, 1)
else :
target = Vector2(0, 270)
closed_node = null
button_4_status = true
parent_node.move_child(upgrade_node2, 1)
func _on_open_generator2_pressed() -> void:
target_node = generator_node2
if button_1_status or button_2_status or button_4_status :
target = Vector2(0,270)
closed = Vector2(0,720)
button_1_status = false
button_2_status = false
button_3_status = true
button_4_status = false
parent_node.move_child(generator_node2, 1)
elif button_3_status :
closed_node = null
target = Vector2(0, 720)
button_3_status = false
parent_node.move_child(generator_node2, 1)
elif !button_3_status and closed_node != null :
target = Vector2(0, 270)
closed_node = null
button_3_status = true
parent_node.move_child(generator_node2, 1)
else :
target = Vector2(0, 270)
closed_node = null
button_3_status = true
parent_node.move_child(generator_node2, 1)