32 lines
724 B
GDScript
32 lines
724 B
GDScript
extends RigidBody3D
|
|
|
|
@export var health := 1
|
|
@export var explosion_particles: PackedScene
|
|
@export var break_sound: AudioStream
|
|
|
|
func take_damage(damage: int):
|
|
health -= damage
|
|
|
|
if health <= 0:
|
|
destroy()
|
|
|
|
func destroy():
|
|
# Partikeleffekt spawnen
|
|
if explosion_particles:
|
|
var particles = explosion_particles.instantiate()
|
|
get_parent().add_child(particles)
|
|
particles.global_position = global_position
|
|
|
|
# Sound abspielen
|
|
if break_sound:
|
|
var audio = AudioStreamPlayer3D.new()
|
|
get_parent().add_child(audio)
|
|
audio.stream = break_sound
|
|
audio.global_position = global_position
|
|
audio.play()
|
|
# Auto-cleanup nach Sound
|
|
audio.finished.connect(func(): audio.queue_free())
|
|
|
|
# Würfel entfernen
|
|
queue_free()
|