private void SetBuildMode(bool isBuildMode) { rb.isKinematic = isBuildMode; if (isBuildMode) { sailState = SailingState.SLOW; SetSailsToState(sailState); } }
private void SetSailsToState(SailingState _state) { // Sail state can be set to slow if it's build mode if (_state == SailingState.SLOW) { if (!GameState.BuildMode) { AudioManager.instance.PlaySound(slowDownSound); } UI.GoingFast(false); components.LowerSails(); } // the other two states cannont be accessed if it's in build mode if (!GameState.BuildMode) { if (_state == SailingState.IDLE) { components.RaiseSails(); components.FullSpeed(false); UI.GoingFast(false); CC.DisableFastMode(); } else if (_state == SailingState.SLOW) { CC.DisableFastMode(); UI.GoingFast(false); components.FullSpeed(false); } else if (_state == SailingState.FAST) { AudioManager.instance.PlaySound(fullSpeedSound); components.LowerSails(); components.FullSpeed(true); UI.GoingFast(true); CC.EnableFastMode(); } } }
private void Update() { if (!GameState.BuildMode && !GameState.Paused && canMove) { // steering steering = Input.GetAxis("Horizontal") * turnSpeed * Time.deltaTime; if (steering != 0) { if (Mathf.Abs(rudder) < maxRoll) { rudder += steering; } } else { rudder = Mathf.MoveTowards(rudder, 0f, turnSpeed * 2 * Time.deltaTime); } // Switch between fast and slow mode if (Input.GetButtonDown("A_Button")) { if (components.getSpeedBonus() > 0) { if (sailState == SailingState.SLOW) { sailState = SailingState.FAST; } else { sailState = SailingState.SLOW; } SetSailsToState(sailState); } } if (Input.GetButton("B_Button")) { idleChargeUp += 1 * Time.deltaTime; if (idleChargeUp > idleHoldTime) { if (sailState != SailingState.IDLE) { sailState = SailingState.IDLE; SetSailsToState(sailState); } } } else { idleChargeUp = 0; } if (Time.deltaTime != 0) { velocity = (transform.position - previousPos) / Time.deltaTime; previousPos = transform.position; } } }