extends Node3D ##闸机门 class_name GateDoor @onready var left_animation_player: AnimationPlayer = $LeftAnimationPlayer @onready var right_animation_player: AnimationPlayer = $RightAnimationPlayer ## 闸机门的状态枚举 enum Gate_Door_STATE{ opening,# 正在开门 open,#开到位 closeing,#正在关门 close,# 关到位 } ##闸机门的状态 @onready var gateDoorState : Gate_Door_STATE = Gate_Door_STATE.close : set(value): if gateDoorState != value: gateDoorState = value if gateDoorState == Gate_Door_STATE.open : left_animation_player.play("leftOpen") right_animation_player.play("rightOpen") elif gateDoorState == Gate_Door_STATE.close : left_animation_player.play("leftClose") right_animation_player.play("rightClose") ##打开闸机门 func openGateDoor ()-> void: if gateDoorState == Gate_Door_STATE.close : gateDoorState = Gate_Door_STATE.open ##关闭闸机门 func closeGateDoor ()-> void: if gateDoorState == Gate_Door_STATE.open : gateDoorState=Gate_Door_STATE.close var waitPeopleCount = 0 func _on_area_3d_area_entered(area: Area3D) -> void: var peopleWalkFollow = area.get_parent().get_parent() if peopleWalkFollow is PlayerPathFollow : waitPeopleCount += 1 openGateDoor() func _on_area_3d_area_exited(area: Area3D) -> void: var peopleWalkFollow = area.get_parent().get_parent() if peopleWalkFollow is PlayerPathFollow : waitPeopleCount -= 1 if waitPeopleCount==0 : closeGateDoor()