Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Node
- class_name StateMachine
- var states: Dictionary={}
- var current_state: State
- func _ready():
- yield(get_parent(), "ready")
- for state in get_children():
- states[state.name] = state
- for state in get_children():
- state.states = self.states
- state.player = get_parent()
- current_state = states["Idle"]
- enter_state()
- func enter_state() -> void:
- current_state.enter()
- func _physics_process(_delta):
- current_state.logic()
- if current_state.get_transition() != null:
- change_state(current_state.get_transition())
- func change_state(nextState: State) -> void:
- current_state = nextState
- enter_state()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement