Godot 4.4
I’m trying to make a drag-and-drop inventory system. I want it so that when the tool is dragged to the box, the texture of the box changes. However, the tool doesn’t affect the box when it is dragged to it.
Here is what the scene tree looks like:
Here is the code for the tool:
extends Sprite2D
var dragging = false
var of = Vector2(0,0)
func _process(delta: float) -> void:
if dragging:
position = get_global_mouse_position() - of
func _on_tool_button_button_down() -> void:
dragging = true
Global.DRAGGINGTOOL = true
of = (get_global_mouse_position() - global_position)
func _on_tool_button_button_up() -> void:
dragging = false
position.x = 226
position.y = 356
await get_tree().create_timer(5).timeout
Global.DRAGGINGTOOL = false
Here is the code for the box:
extends Sprite2D
var box_closed = preload("res://sprites/prerendered_sprites/boxscene.png")
var box_open = preload("res://sprites/prerendered_sprites/boxbrokenscene.png")
@onready var tool_area_2d: Area2D = $"../ToolIcon/ToolButton/ToolArea2D"
func _on_area_2d_body_entered(body: Node2D) -> void:
if body == tool_area_2d and Global.DRAGGINGTOOL == true:
texture = box_open
Is there a better way to go about this?


