void Update() { // we OR the inputs, as they're only used on a tick, we store it until frame is done var NewAxisReading = (int)Input.GetAxisRaw(JoystickAxisName); bool LeftDown = (NewAxisReading < 0) && (LastAxisReading >= 0); bool RightDown = (NewAxisReading > 0) && (LastAxisReading <= 0); LastAxisReading = NewAxisReading; if (LeftDown || Input.GetKeyDown(LeftKey)) { if (TickStart_Direction == PopperMan.Direction.Up) { Direction = PopperMan.Direction.Left; } else if (TickStart_Direction == PopperMan.Direction.Left) { Direction = PopperMan.Direction.Down; } else if (TickStart_Direction == PopperMan.Direction.Down) { Direction = PopperMan.Direction.Right; } else if (TickStart_Direction == PopperMan.Direction.Right) { Direction = PopperMan.Direction.Up; } } else if (RightDown || Input.GetKeyDown(RightKey)) { if (TickStart_Direction == PopperMan.Direction.Up) { Direction = PopperMan.Direction.Right; } else if (TickStart_Direction == PopperMan.Direction.Left) { Direction = PopperMan.Direction.Up; } else if (TickStart_Direction == PopperMan.Direction.Down) { Direction = PopperMan.Direction.Left; } else if (TickStart_Direction == PopperMan.Direction.Right) { Direction = PopperMan.Direction.Down; } } }
public void ClearInput() { if (Alive) { if (Direction != TickStart_Direction) { OnPlayerChangedDir.Invoke(); } } TickStart_Direction = Direction; /* * // work out if we let-go in a frame * Input_Direction = PopperMan.Direction.None; * SetDirectionIfKey( PopperMan.Direction.Up, PopperMan.NesPadJoystickButton.Up ); * SetDirectionIfKey( PopperMan.Direction.Down, PopperMan.NesPadJoystickButton.Down ); * SetDirectionIfKey( PopperMan.Direction.Left, PopperMan.NesPadJoystickButton.Left ); * SetDirectionIfKey( PopperMan.Direction.Right, PopperMan.NesPadJoystickButton.Right ); * TickStart_Direction = Input_Direction; * Input_Direction = PopperMan.Direction.None; */ }
void Start() { // avoid first erroneous change-dir detection TickStart_Direction = Direction; }