godot-webrtc-mplayer-testing/scripts/objects/destructable.gd

21 lines
427 B
GDScript3
Raw Permalink Normal View History

2021-12-17 17:10:56 -06:00
extends CollisionShape2D
class_name Destructable
signal hit(damage, collision)
signal die(damage, collision)
export var max_health = 100
export var health = 100
func _ready():
pass
func trigger_hit(damage, collision):
emit_signal("hit", damage, collision)
health = clamp(health - damage, -max_health, max_health)
if health > max_health:
health = max_health
elif health <= 0:
emit_signal("die", damage, collision)