Hi, i'm using godot for maybe 3 months. I have a Scene called Pistol, and it haves an Are2D node responsible for detects if the player enters his area, and after that, store the value in a Global variable called take_weapon.
In another Scene, called Mundo (World in portuguese) i'm going to use that value to delete the instance that i've created for the Pistol Scene, thing is, for some reason i can't delete the instance.
Sorry if it was hard to understand, english is not my main language. Here's the code of my game to help you guys. Thanks in advance.
Mundo
- Player
- AnimatedSprite
- CollisionShape2D
- TileMap
extends Node2D
var pistolPath = preload("res://Pistol.tscn")
var count = 0
func _ready():
pass
func process(delta):
var p = pistolPath.instance()
while count == 0:
getparent().add_child(p)
count += 1
if Global.take_weapon == false:
print("False")
elif Global.take_weapon == true:
print("True")
elif Global.take_weapon == null:
print("Null")
if Global.take_weenter code hereapon == true:
p.queue_free()
else:
pass
Pistol
- AnimatedSprite
- Area2D
- CollisionShape2D
extends Node2D
var onfloor = true
var cantake
func process(delta):
if onfloor:
$AnimatedSprite.play("idle")
else:
$AnimatedSprite.play("usando")
Global.take_weapon = can_take
func onArea2Dbodyentered(body):
can_take = true
func onArea2Dbodyexited(body):
can_take = false