private void GetShaftAndGo(Directions direction) { currentShaft = connectingShafts[(int)direction]; if (currentShaft == null || currentShaft.waypoints.Count == 0) { Debug.Log("No shaft detected in direction " + direction); } phase = ElevatorPhase.ElevatorMoving; currentWaypoint = 0; }
private void ShutDoors() { phase = ElevatorPhase.DoorsClosing; rightDoor.Close(); leftDoor.Close(); }
private void OpenDoors() { phase = ElevatorPhase.DoorsOpening; rightDoor.Open(); leftDoor.Open(); }
public MovementStateType PassengerFixedUpdate(Dictionary <CommandType, bool> commandList) { switch (phase) { case ElevatorPhase.DoorsOpen: if (commandList[CommandType.Kneel] || cancelPressed) { exitingElevator = true; return(MovementStateType.STANDING); } if (commandList[CommandType.MoveLeft] || commandList[CommandType.MoveRight]) { exitingElevator = true; return(MovementStateType.STANDING); } timeDoorsOpen += Time.deltaTime; if (timeDoorsOpen > 3.5f || commandList[CommandType.Jetpack]) { ShutDoors(); timeDoorsOpen = 0f; } break; case ElevatorPhase.DoorsClosing: if (IsDoorClosed()) { phase = ElevatorPhase.WaitingForInstruction; } else { if (commandList[CommandType.Kneel] || cancelPressed) { OpenDoors(); } } break; case ElevatorPhase.DoorsOpening: if (IsDoorOpen()) { phase = ElevatorPhase.DoorsOpen; } break; case ElevatorPhase.WaitingForInstruction: if (cancelPressed) { OpenDoors(); } else if (commandList[CommandType.Kneel]) { GetShaftAndGo(Directions.Down); } else if (commandList[CommandType.Jetpack]) { GetShaftAndGo(Directions.Up); } else if (commandList[CommandType.MoveLeft]) { GetShaftAndGo(Directions.Left); } else if (commandList[CommandType.MoveRight]) { GetShaftAndGo(Directions.Right); } break; case ElevatorPhase.ElevatorMoving: carriage.position = Vector2.MoveTowards( carriage.position, currentShaft.waypoints[currentWaypoint], carriageSpeed * Time.deltaTime); if (Mathf.Approximately(carriage.position.x, currentShaft.waypoints[currentWaypoint].x) && Mathf.Approximately(carriage.position.y, currentShaft.waypoints[currentWaypoint].y)) { if (++currentWaypoint >= currentShaft.waypoints.Count) { // arrived phase = ElevatorPhase.DoorsOpening; } } break; } cancelPressed = false; return(MovementStateType.NONE); }