Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Xenapibe |
How can I access player’s sprite in global script ?
Godot Version : 3.5.1
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Xenapibe |
How can I access player’s sprite in global script ?
Godot Version : 3.5.1
Reply From: | SteveSmith |
In the player’s script, set the global variable to the player, e.g. Globals.player = self. Then other scripts can access it, e.g. var player = Globals.player.
I want to make a store system to my game. But I have issue in buy menu. When I pressed the buy button my character sprite doesn’t change.
My buy function
func _on_BuyCharacter_pressed():
if GlobalLevel.GlobalCoin >= 0:
$StorePanel/CharacterBuy/Sold.visible = true
$StorePanel/CharacterBuy/Goblin.self_modulate = Color.crimson
$StorePanel/CharacterBuy/Locked.visible = true
$StorePanel/CharacterBuy/Goblin/Particles2D.visible = false
GlobalLevel.GlobalCoin = GlobalLevel.GlobalCoin - 0
$CollectedCoins.text = str(GlobalLevel.GlobalCoin)
GlobalLevel.skinChanged()
GlobalLevel.save_skin()
GlobalLevel.save_coin()
my Global script
var player = null
func skinChanged():
if player:
player.get_node("Sprite").texture = load("res://sprites/Goblin.png")
save_skin()
Xenapibe | 2022-12-01 09:15