Hello all! I am trying to spawn a key once the player collects a certain amount of coins and I need it to spawn in a precise position on the map. I have a script that keeps track of coins collected and I'd like to place the code here if possible:
extends CanvasLayer
var coins = 0
onready var key = $Key
var hasKey := false
var keyload = preload("res://Resources/Key.tscn")
func _ready():
$Coins.text = String(coins)
load_hearts()
Global.hud = self
func _on_coin_collected():
coins = coins + 1
_ready()
if coins == 01:
var scene = load("res://Resources/Key.tscn")
var keyload = scene.get_instance_id()
SoundPlayer.play_sound(SoundPlayer.SOUNDKEY)
print("key should appear and should hear sound")
#add_child(keyload)
#get_tree().change_scene("res://YouWinScreen.tscn")
I'm not sure if my spawn code is correct either. Would it be easier I just toggle visibility/collision mask? if anyone could offer some tips here I'd be forever grateful! 🙂