Владимир Слыжук
Знаток
(365)
2 месяца назад
extends Node2D
export var shop_scene = preload("res://scenes/Shop.tscn") # The shop scene
var shop_instance = null
var is_shop_visible = false
func _on_shop_pressed():
if not is_shop_visible:
if shop_instance == null:
shop_instance = shop_scene.instantiate()
get_tree().get_root().add_child(shop_instance)
shop_instance.get_node("AnimationPlayer").play("SlideIn")
else:
shop_instance.get_node("AnimationPlayer").play("SlideIn")
is_shop_visible = true
else:
shop_instance.get_node("AnimationPlayer").play("SlideOut")
is_shop_visible = false
Егор ЧочУченик (109)
2 месяца назад
выдает ошибку - Attempt to call function 'play' in base 'null instance' on a null instance.
func _on_shop_pressed() -> void:
if not is_shop_visible:
_shop_instance = shopin.instantiate()
get_tree().get_root().add_child(_shop_instance)
_animation_player = _shop_instance.get_node("AnimationPlayer")
_animation_player.play("SlideIn")
is_shop_visible = true
else:
_animation_player.stop() # Stop the first animation
get_tree().get_root().remove_child(_shop_instance)
_shop_instance = shopout.instantiate()
get_tree().get_root().add_child(_shop_instance)
_animation_player = _shop_instance.get_node("AnimationPlayer")
_animation_player.play("shopout")
is_shop_visible = false
$store.play()