for node in hand_block.get_children():
node.visible = false
hand_block.get_node(slot_item.item_name).visible = true
how to simplify my code?
Asked Answered
maybe you can use add_to_group.
Set when initializing nodes
grass_node:
node.add_to_group("block_grass")
node.add_to_group("all_block")
stone_node:
node.add_to_group("block_stone")
node.add_to_group("all_block")
calling method
get_tree().call_group("all_block","set_visible",false)
get_tree().call_group(slot_item.item_name,"set_visible",true)
or
for node in hand_block.get_children():
if node.is_in_group("all_block"):
if node.is_in_group(slot_item.item_name):
node.visible = true
else:
node.visible = false
© 2022 - 2024 — McMap. All rights reserved.