// Update is called once per frame void Update() { if (fadingOut) { fadeTime -= Time.deltaTime; if (fadeTime <= 0) { SceneManager.LoadScene(menuSceneName); } else { Color originalColor = fadeInOutImage.color; originalColor.a = 1 - fadeInOutCurve.Evaluate(fadeTime / fadeOutDuration); fadeInOutImage.color = originalColor; } } else if (fadeTime < fadeInDuration) { fadeTime = Mathf.Min(fadeTime + Time.deltaTime, fadeInDuration); Color originalColor = fadeInOutImage.color; originalColor.a = 1 - fadeInOutCurve.Evaluate(fadeTime / fadeInDuration); fadeInOutImage.color = originalColor; } else if (fadeOutEnabled && (Input.GetMouseButtonDown(0) || MobileInput.GetTouchUp())) { fadingOut = true; fadeTime = fadeOutDuration; } }
void Update() { if (playerLost) { // if (!playerHitGround) // { transform.RotateAround(Vector3.zero, fallingSphericalMovementVector, fallingSphericalMovementVector.magnitude * Time.deltaTime); transform.position = transform.position.normalized * Mathf.Max(0, transform.position.magnitude - fallSpeedOnDeathCurve.Evaluate(deadTime) * Time.deltaTime); // } deadTime += Time.deltaTime; if (playerHitGround && (Input.GetButtonDown("Boost") || MobileInput.GetTouchUp())) { Application.LoadLevel(Application.loadedLevel); } } }
// Update is called once per frame void Update() { if (rotating) { // Get rotation delta float previousAngle = rotationCurve.Evaluate(rotationValue / rotationTime); rotationValue += Time.deltaTime; if (rotationValue > 1) { rotating = false; rotationValue = 1; } float newAngle = rotationCurve.Evaluate(rotationValue / rotationTime); float rotationDelta = (newAngle - previousAngle) * totalDesiredRotationDelta; // Rotate around y axis transform.Rotate(Vector3.up, rotationDelta, Space.Self); } else { if (Input.GetKeyDown("right") || MobileInput.GetSwipedLeft()) { RotateToNextObject(); } else if (Input.GetKeyDown("left") || MobileInput.GetSwipedRight()) { RotateToPreviousObject(); } else if (Input.GetKeyDown("space") || Input.GetKeyDown("enter") || Input.GetMouseButtonDown(0) || MobileInput.GetTouchUp()) { menuOptions[selectedMenuOption].PerformAction(); } } }
// Update is called once per frame void Update() { ReduceTimerIfDamaged(); // Update Effects while boosting if (mobileInputMode ? MobileInput.GetTouchDown() : Input.GetButtonDown("Boost")) { trailEffectsManager.StartCharging(); } // Slow down and charge if (mobileInputMode ? MobileInput.GetTouched() : Input.GetButton("Boost")) { bool previouslyCharged = speedCharge >= maxChargeTime; speedCharge += Time.deltaTime; RainFromCharge(rainFromChargeDistance, playerRainRadius); if (!previouslyCharged && speedCharge >= maxChargeTime) { trailEffectsManager.BoostReady(); } } // return to glide if (sphericalMovementVector.magnitude > minGlideSpeed) { sphericalMovementVector = sphericalMovementVector.normalized * Mathf.Max(minGlideSpeed, sphericalMovementVector.magnitude - Time.deltaTime * returnToGlideRate); } // Get input Vector3 movementDirectionScreenSpace = Camera.main.transform.InverseTransformDirection(Vector3.Cross(sphericalMovementVector, transform.position)).normalized; Vector3 inputDirection = Vector3.zero; if (mobileInputMode) { if (Input.touchCount > 0) { // flatten screen space position Vector3 positionScreenSpace = Camera.main.WorldToScreenPoint(transform.position); movementDirectionScreenSpace.z = 0; // Convert touch to 3d vector Vector3 touchPositionScreenSpace = new Vector3(Input.touches [0].position.x, Input.touches [0].position.y, 0); inputDirection = (positionScreenSpace - touchPositionScreenSpace) / minTouchDistanceFromPlayerToTurnScreenSpace; inputDirection *= -1; previousInputMovementDirection = inputDirection; } else { inputDirection = previousInputMovementDirection; } } else if (mouseInputMode) { if (Input.GetButton("Boost")) { Vector3 positionScreenSpace = Camera.main.WorldToScreenPoint(transform.position); movementDirectionScreenSpace.z = 0; inputDirection = (positionScreenSpace - Input.mousePosition) / minMouseDistanceFromPlayerToTurnScreenSpace; inputDirection *= -1; previousInputMovementDirection = inputDirection; } else { inputDirection = previousInputMovementDirection; } } else { inputDirection = (new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0)); inputDirection *= 1.5f; if (inputDirection.magnitude > 1.0f) { inputDirection = inputDirection.normalized; } } // Steer and brake inputDirection.z = 0; Steer(inputDirection, movementDirectionScreenSpace, mobileInputMode ? MobileInput.GetTouched() : Input.GetButton("Boost")); // Push to above min speed if (sphericalMovementVector.magnitude < minSpeed) { sphericalMovementVector = minSpeed * sphericalMovementVector.normalized; } // Move transform.RotateAround(Vector3.zero, sphericalMovementVector, sphericalMovementVector.magnitude * Time.deltaTime); // Boost if (mobileInputMode ? MobileInput.GetTouchUp() : Input.GetButtonUp("Boost")) { // If we've been charging long enough if (speedCharge >= maxChargeTime) { Quaternion boostDirectionTurn = Quaternion.AngleAxis(boostTurnAmount, transform.position); sphericalMovementVector = (Mathf.Min(1f, speedCharge / maxChargeTime) * (maxBoostSpeed - minBoostSpeed) + minBoostSpeed) * (boostDirectionTurn * sphericalMovementVector.normalized); if (sphericalMovementVector.magnitude > maxSpeed) { sphericalMovementVector = sphericalMovementVector.normalized * maxSpeed; } // Shake camera Vector3 shakeDirection = Camera.main.transform.InverseTransformDirection(Vector3.Cross(sphericalMovementVector, transform.position)); shakeDirection.z = 0; shakeDirection.Normalize(); Camera.main.GetComponent <CameraShaker>().ShakeInDirectionWithIntensity(shakeDirection, boostCameraShakeIntensity, CameraShaker.ShakeType.Smooth); trailEffectsManager.Boost(); RainFromBoost(rainFromBoostDistance, playerRainRadius, rainFromBoostSpreadDegrees); } boostTurnAmount = 0; speedCharge = 0f; trailEffectsManager.StopCharging(); } // Look Vector3 lookDirection = Quaternion.AngleAxis(boostTurnAmount, transform.position) * sphericalMovementVector; directionIndicator.transform.rotation = Quaternion.LookRotation(lookDirection, transform.position.normalized); // Update Visual Components trailEffectsManager.UpdateMovement(sphericalMovementVector, lookDirection, maxChargeDirectionAngle); trailEffectsManager.UpdateSpeed((sphericalMovementVector.magnitude - minSpeed) / (maxSpeed - minSpeed)); }