extends Node3D
@onready var pickup_mess = $Control
@onready var playersight = $"../CharacterBody3D/head/RayCast3D"
@onready var sho2_thing = $"../Control2/Label"
var amount_of_thing = 0
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
@warning_ignore("unused_parameter")
func _process(delta):
if playersight.is_colliding():
pickup_mess.show()
else:
pickup_mess.hide()
if playersight.is_colliding() and Input.is_action_just_pressed("pick up"):
amount_of_thing += 1
sho2_thing.text = str(amount_of_thing)
queue_free()
if amount_of_thing == 2:
get_tree().quit()
what is this? Can you explain what you expect to happen versus what really happens?
what i want happen is that you can pick the items to quit but when add multiple and pick up one all get removed
The way you are using playersight doesn’t care what it’s looking at, only that it is or is not looking at something. You may want to check if the object being looked at is this object, it may be much easier to do that if the script is attached directly to the colliding object so you could check with self
if playersight.get_collider() == self:
Or a better version would instead be scripted on the player, checking what they ray cast against and using a defined “interact” function
# interactable.gd
extends Area3D
class_name Interactable
func interact() -> void:
amount_of_thing += 1
queue_free()
# player.gd
@onready var sight: RayCast3D = $RayCast3D
func _process(_delta) -> void:
if sight.is_colliding():
var collider := sight.get_collider()
if collider is Interactable:
collider.interact()
i tired something else and now it just shows one when i pick multiple
extends Node3D
extends Node3D
@onready var pickup_mess = $Control
@onready var playersight = $"../CharacterBody3D/head/RayCast3D"
@onready var sho2_thing = $"../Control2/Label"
var amount_of_thing = 0
var inshight = 0
# Called when the node enters the scene tree for the first time.
func _ready():
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
@warning_ignore("unused_parameter")
func _process(delta):
if playersight.is_colliding() and playersight.get_collider() == self:
inshight = 1
pickup_mess.show()
else:
inshight = 0
pickup_mess.hide()
if inshight == 1 and Input.is_action_just_pressed("pick up"):
amount_of_thing += 1
sho2_thing.text = str(amount_of_thing)
queue_free()
if amount_of_thing == 2:
get_tree().quit()
Not sure I understand but this variable is local to each object, every object has their own amount_of_thing starting at zero, if you select an object it’ll add one to it’s specific amount_of_thing before being deleted. The highest value amount_of_thing will ever be is 1. Is this text what you mean by “shows one”?
The quick solution is to make this a static var, but I feel it would be better to again put this variable on the player script