In my 2D platformer game, I'm trying to create a button that, when the player or a box is on top of it, opens a door of the same color. Here is the code for the button:
extends StaticBody2D
onready var is_object_on_button = false
func _on_Green_Button_Area_body_entered(body):
is_object_on_button = true
print("button is down")
func _on_Green_Button_Area_body_exited(body):
is_object_on_button = false
print("button is up")
Code for the door:
extends StaticBody2D
onready var is_object_on_button = Green_Button.is_object_on_button
onready var door_collision = $CollisionPolygon2D
func _process(delta):
if is_object_on_button:
door_collision.set_disabled(true)
print("unlocked")
else:
door_collision.set_disabled(false)
print("locked")
The button prints the right things at the right time, so I assume the button is working properly, but the door constantly stays (and prints) locked. How do I fix this?
Edit: After a bit of experimentation, I think that the problem is that is_object_on_button keeps returning to whatever value its assigned at the start: If I set it to true at the onready, it stays true. I do not know how to fix this, either.