private Vector3 originalPosition; private float shakeDuration = 0f; private float shakeMagnitude = 0.1f;
// Apply movement Vector3 movement = transform.forward * currentSpeed * Time.fixedDeltaTime; rb.MovePosition(rb.position + movement); // Apply turning with drift effect float turnAngle = currentTurn; if (isDrifting) turnAngle *= driftTurnMultiplier; currentDriftAngle = Mathf.Lerp(currentDriftAngle, turnAngle, Time.deltaTime * 5f); Quaternion turnRotation = Quaternion.Euler(0f, turnAngle, 0f); rb.MoveRotation(rb.rotation * turnRotation);
MoveVehicle();
void OnTriggerEnter(Collider other)
float originalTurnMultiplier = driftTurnMultiplier; driftTurnMultiplier *= 0.8f; yield return new WaitForSeconds(0.5f); driftTurnMultiplier = originalTurnMultiplier;
if (Instance == null) Instance = this; else Destroy(gameObject);
void EndDrift()
using UnityEngine; using System.Collections; public class CameraShake : MonoBehaviour
if (postProcessVolume.profile.TryGetSettings(out vignette) && postProcessVolume.profile.TryGetSettings(out motionBlur) && postProcessVolume.profile.TryGetSettings(out chromaticAberration)) // Initialize settings
// Update speed display float displaySpeed = currentSpeed * 3.6f; // Convert to km/h speedText.text = Mathf.RoundToInt(displaySpeed).ToString() + " km/h"; // Update boost slider if (isBoosting) boostSlider.value = 1 - (currentBoostTime / boostDuration); else boostSlider.value = (float)currentBoostCharges / maxBoostCharges; // Update boost color boostFillImage.color = boostGradient.Evaluate(boostSlider.value); // Update boost charges text boostChargesText.text = currentBoostCharges.ToString() + " / " + maxBoostCharges.ToString(); // Speed-based UI effects float speedPercentage = currentSpeed / maxSpeed; speedText.color = Color.Lerp(Color.white, Color.red, speedPercentage); extreme race game unity
if (currentCooldown > 0) currentCooldown -= Time.deltaTime; // Recharge boost if (currentBoostCharges < maxBoostCharges && !isBoosting) currentRechargeTimer += Time.deltaTime; if (currentRechargeTimer >= boostRechargeRate) currentBoostCharges++; currentRechargeTimer = 0;
void Start()
isRacing = false; raceCompletePanel.SetActive(true); raceCompleteText.text = $"Race Complete!\nLaps: laps\nTime: timerText.text"; private Vector3 originalPosition