Skip to content

Instantly share code, notes, and snippets.

@WolfgangSenff
Created December 18, 2022 10:46
Show Gist options
  • Save WolfgangSenff/827b8daf74e4f63312a7d0c9d053d904 to your computer and use it in GitHub Desktop.
Save WolfgangSenff/827b8daf74e4f63312a7d0c9d053d904 to your computer and use it in GitHub Desktop.
Calling functions on other scripts in Godot
# In your Enemy.gd script
...
const KILL_EFFECT_SCENE = preload(...)
func take_damage(amount: float) -> void:
enemy_stats.hitpoints -= amount
if enemy_stats.hitpoints <= 0:
kill()
func kill() -> void:
queue_free()
spawn_effect()
func spawn_effect() -> void:
var ke = Globals.spawn_instance_on_main(KILL_EFFECT_SCENE)
ke.set_points_label(enemy_stats.point_value) # IMPORTANT!!!!
# Now, in your kill effect scene, add a script on the root node...
extends Particles2D
func _ready() -> void:
start_countdown()
func set_points_label(points: int) -> void:
$PointsLabel.text = points
# can tween the points label so it looks more interesting or do any other effects you want with it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment