public void Update() { if (_currentState != null) { _currentState.Execute(); } }
private void Update() { bool changedState = false; if (_currentState != null) { _currentState.Execute(this); } if ((Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) && (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))) { idle = true; walking = false; running = false; backwards = false; changedState = true; } //Check if input for walking is given else if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow)) { idle = false; CheckShift(); changedState = true; } //Check if input for walking backwards is given else if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow)) { idle = false; backwards = true; CheckShift(); changedState = true; } //Check if input for starting to spring is given if (Input.GetKeyDown(KeyCode.LeftShift)) { if (walking) { walking = false; running = true; changedState = true; } } if (Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.UpArrow)) { if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) { idle = false; backwards = true; if (Input.GetKey(KeyCode.LeftShift)) { running = true; } else { walking = true; } } else { idle = true; walking = false; running = false; backwards = false; } changedState = true; } if (Input.GetKeyUp(KeyCode.S) || Input.GetKeyUp(KeyCode.DownArrow)) { backwards = false; if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) { idle = false; if (Input.GetKey(KeyCode.LeftShift)) { running = true; } else { walking = true; } } else { idle = true; walking = false; running = false; backwards = false; } changedState = true; } if (Input.GetKeyUp(KeyCode.LeftShift)) { if (running) { walking = true; running = false; changedState = true; } } if (changedState) { FindState(); } }