Files
fps_project_1/scripts/switch_basic.gd
2025-03-30 18:44:54 -05:00

59 lines
1.2 KiB
GDScript

extends Node
class_name SwitchBasic
signal switch_changed
@export var switch_override : bool = false
@export var start_on : bool = false
@export var toggle_enabled : bool = false
@export var bullet_enabled : bool = true
@export var timer_enabled : bool = false
@export var timer_duration : float = 2.0
@export var anim_player : AnimationPlayer
var switched_on : bool
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
add_to_group("switch")
add_to_group("interact")
switched_on = start_on
func switch():
if toggle_enabled:
if switched_on == true:
switched_on = false
switch_changed.emit()
if anim_player != null:
anim_player.play("off")
else:
switched_on = true
switch_changed.emit()
if anim_player != null:
anim_player.play("on")
if timer_enabled:
start_timer()
else:
switched_on = true
switch_changed.emit()
if anim_player != null:
anim_player.play("on")
if timer_enabled:
start_timer()
func start_timer():
await get_tree().create_timer(timer_duration).timeout
_on_timer_timeout()
func _on_timer_timeout():
switched_on = false
switch_changed.emit()