godot-psd-training/sceen/platform/elevator/elevator.gd
2024-07-23 19:46:26 +08:00

42 lines
1007 B
GDScript

extends Node3D
class_name Elevator
## 运动方式的枚举
enum Exercise_type{
corotation, #正转(下行)
reversal, #反转(上行)
}
var currentExerciseType = Exercise_type.corotation
func useKeyChangeExerciseType() -> void:
if currentExerciseType == Exercise_type.corotation :
reversalElevator()
else :
corotationElevator()
#正转
func corotationElevator() -> void:
currentExerciseType = Exercise_type.corotation
$key.visible = true
await get_tree().create_timer(0.5).timeout
$key.rotation.x = -90
$keyhole.rotation.x = -90
$AnimationPlayer.play('pedal00100')
await get_tree().create_timer(2).timeout
$key.visible = false
$key.rotation.x = 0
#反转
func reversalElevator() -> void:
currentExerciseType = Exercise_type.reversal
$key.visible = true
await get_tree().create_timer(0.5).timeout
$key.rotation.x = 90
$keyhole.rotation.x = 90
$AnimationPlayer.play_backwards('pedal00100')
await get_tree().create_timer(2).timeout
$key.visible = false
$key.rotation.x = 0