// Update is called once per frame void Update() { // we check inputs and if buttons are pressed, the appropriate events will be fired #region "Forward (W)" if (Input.GetKeyDown(KeyCode.W)) { OnForwardKeyPressed?.Invoke(); } if (Input.GetKey(KeyCode.W)) { OnForwardKeyHold?.Invoke(); } if (Input.GetKeyUp(KeyCode.W)) { OnForwardKeyReleased?.Invoke(); } #endregion #region "Backward (S)" if (Input.GetKeyDown(KeyCode.S)) { OnBackwardKeyPressed?.Invoke(); } if (Input.GetKey(KeyCode.S)) { OnBackwardKeyHold?.Invoke(); } if (Input.GetKeyUp(KeyCode.S)) { OnBackwardKeyReleased?.Invoke(); } #endregion #region "Left (A)" if (Input.GetKeyDown(KeyCode.A)) { OnLeftKeyPressed?.Invoke(); } if (Input.GetKey(KeyCode.A)) { OnLeftKeyHold?.Invoke(); } if (Input.GetKeyUp(KeyCode.A)) { OnLeftKeyReleased?.Invoke(); } #endregion #region "Right (D)" if (Input.GetKeyDown(KeyCode.D)) { OnRightKeyPressed?.Invoke(); } if (Input.GetKey(KeyCode.D)) { OnRightKeyHold?.Invoke(); } if (Input.GetKeyUp(KeyCode.D)) { OnRightKeyReleased?.Invoke(); } #endregion #region "Running (Left Shift)" if (Input.GetKeyDown(KeyCode.LeftShift)) { OnRunningKeyPressed?.Invoke(); } if (Input.GetKey(KeyCode.LeftShift)) { OnRunningKeyHold?.Invoke(); } if (Input.GetKeyUp(KeyCode.LeftShift)) { OnRunningKeyReleased?.Invoke(); } #endregion #region "Left Click (Mouse1)" if (Input.GetMouseButtonDown(0)) { OnLeftClickPressed?.Invoke(); } if (Input.GetMouseButton(0)) { OnLeftClickHold?.Invoke(); } if (Input.GetMouseButtonUp(0)) { OnLeftClickReleased?.Invoke(); } #endregion #region "Right Click (Mouse2)" if (Input.GetMouseButtonDown(1)) { OnRightClickPressed?.Invoke(); } if (Input.GetMouseButton(1)) { OnRightClickHold?.Invoke(); } if (Input.GetMouseButtonUp(1)) { OnRightClickReleased?.Invoke(); } #endregion #region "Jump (Spacebar)" if (Input.GetKeyDown(KeyCode.Space)) { OnJumpButtonPressed?.Invoke(); } #endregion #region "Lock On (F)" if (Input.GetKeyDown(KeyCode.F)) { OnLockOnButtonPressed?.Invoke(); } #endregion }
// Update is called once per frame void Update() { if (rb.velocity.y != 0) { return; } switch (state) { case State.WAITING: if ((lClick && Input.GetMouseButton(1)) || (rClick && Input.GetMouseButton(0))) { OnRestartLevel(); } if (Input.GetMouseButtonDown(0) && !rClick) { OnLeftClickPressed?.Invoke(); lClick = true; state = State.RECEIVED; dtime = 0.0f; } //when one button is engaged we ignore the other else if (Input.GetMouseButtonDown(1) && !lClick) { OnRightClickPressed?.Invoke(); rClick = true; state = State.RECEIVED; dtime = 0.0f; } if (Input.GetMouseButtonUp(0)) { lClick = false; OnLeftClickReleased(); } if (Input.GetMouseButtonUp(1)) { rClick = false; OnRightClickReleased(); } break; case State.RECEIVED: dtime += Time.deltaTime; if (dtime > holdTime) { if (lClick && Input.GetMouseButtonUp(0)) { OnLeftClickReleased(); lClick = false; state = State.WAITING; } //If the player hold then released we don't want to do the normal action else if (rClick && Input.GetMouseButtonUp(1)) { OnRightClickReleased(); rClick = false; state = State.WAITING; } if (!rb.IsTouchingLayers(LayerMask.GetMask("Bubble"))) // Check if there is a bubble at the player location, if not, return to waiting state with an confused animation. { if ((lClick && Input.GetMouseButton(1)) || (rClick && Input.GetMouseButton(0))) { OnRestartLevel(); } Confused(); //Play confused animation Debug.Log("Confused"); } else { Debug.Log("Entering in holding state"); state = State.HOLDING; } } if (lClick && Input.GetMouseButtonUp(0)) { OnLeftClickReleased?.Invoke(); lClick = false; state = State.PROCESSING; ProcessLAction(); } //We only focus our attention on the engaged button else if (rClick && Input.GetMouseButtonUp(1)) { OnRightClickReleased?.Invoke(); rClick = false; state = State.PROCESSING; ProcessRAction(); } break; case State.HOLDING: //at the end of the timer, change action and return to waiting state if (lClick && Input.GetMouseButtonUp(0)) { OnLeftClickReleased(); lClick = false; state = State.WAITING; } // same as for received else if (rClick && Input.GetMouseButtonUp(1)) { OnRightClickReleased(); rClick = false; state = State.WAITING; } dtime += Time.deltaTime; if (dtime > changeTime) { PickUpBubble(); //lClick = false; //rClick = false; state = State.WAITING; } break; case State.PROCESSING: Debug.Log("Processing"); break; case State.WIN: if (Input.GetMouseButtonDown(0)) { OnNextLevel(); } break; } }