Cant figure out how to make it so when something is picked up i can use it

Godot Version

4.6

Question

I cant figure out how to make it so when something is picked up i can use it, also i removed movement code so no need to go thru lots

If you share code, please wrap it inside three backticks or replace the code in the next block:

extends CharacterBody2D

var speed = 100

var player_state


@export var inv: Inv


var weapon_equipped = true
var weapon_cooldown = true
var leafproj = preload("res://scenes/leafproj.tscn")
var weapon = "res://scenes/example_collectable.tscn"
var mouse_loc_from_player = null





func _physics_process(delta):
	mouse_loc_from_player = get_global_mouse_position() - self.position
	print(mouse_loc_from_player)
	

	


	
	
	var mouse_pos = get_global_mouse_position()
	$Marker2D.look_at(mouse_pos)
	
	
	if Input.is_action_just_pressed("left_mouse") and weapon_equipped and weapon_cooldown:
		weapon_cooldown = false
		var leafproj_instance = leafproj.instantiate()
		leafproj_instance.rotation = $Marker2D.rotation
		leafproj_instance.global_position = $Marker2D.global_position
		add_child(leafproj_instance)
		
		
		await get_tree().create_timer(2.4)
		weapon_cooldown = true
	





func collect(item):
	inv.insert(item)

What does “use” mean for you?

You can add a function to your item class called “use” for example, and call that when needed.

Otherwise this isn’t a lot of information to go off of.

like an attack so that its equipped

One approach:

Have a variable which stores the item currently equipped.

When you pick up an item, have it emit a signal that your character listens for. Have the payload of that signal be the item that was picked up.

When the signal is received, change the item variable to the item that was just picked up.