36 lines
931 B
GDScript
36 lines
931 B
GDScript
extends StaticBody3D
|
|
|
|
var baseColor : Color
|
|
var pressedColor : Color
|
|
@onready var Animator = $Animator
|
|
var pressed : bool = false
|
|
var ButtonMaterial : StandardMaterial3D = StandardMaterial3D.new()
|
|
|
|
func _initButton(BaseColor:Color,PressedColor:Color,char:String):
|
|
baseColor=BaseColor
|
|
pressedColor=PressedColor
|
|
ButtonMaterial.albedo_color = BaseColor
|
|
$Label3D.text = char
|
|
|
|
func _ready() -> void:
|
|
|
|
$MeshRoot.material_override = ButtonMaterial
|
|
ButtonMaterial.albedo_color = baseColor
|
|
Animator.get_animation("interact").loop_mode = Animation.LOOP_NONE
|
|
|
|
func press():
|
|
if !pressed:
|
|
$"..".buttonPressed.emit($Label3D.text)
|
|
$"..".buttonUpdated.emit()
|
|
Animator.play("interact")
|
|
ButtonMaterial.albedo_color = pressedColor
|
|
pressed=true
|
|
|
|
func release():
|
|
if pressed:
|
|
$"..".buttonReleased.emit()
|
|
$"..".buttonUpdated.emit()
|
|
Animator.play_backwards("interact")
|
|
ButtonMaterial.albedo_color = baseColor
|
|
pressed=false
|