Scan to open on your phone
Point a camera at the QR code - it opens this exact paste, no app needed.
https://codepastes.com/fpcswrgcarmainPlain Text
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Runtime.ConstrainedExecution;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public static class GameAssets
{
public static Sprite[] Sprites => menuload.loadedSprites;
public static AudioClip[] AudioClips => menuload.loadedAudioClips;
public static AudioClip[] AudioClips2 => menuload.loadedAudioClipsmod;
}
public class fp : MonoBehaviour
{
private float saveTimer;
private bool Started;
private float pendingCost = 0f;
public AudioSource EngineStartup;
public Scrollbar CameraSoundtrackBaseValue;
public Scrollbar EngineBasicVolumeValue;
public AudioSource Timer;
[Header("Car Physics")]
public float motorTorque = 456f;
public bool Reverse;
public float maxSteerAngle = 40f;
public float brakeTorque = 3200f;
private float ReverbZoneFloat;
public float driftBrakeTorque = 2000f;
public float maxSpeed = 144f;
[Header("Gears & RPM")]
private float rpmMax = 8000f;
private float[] gearRatios = { 3.2f, 2.1f, 1.5f, 1.1f, 0.9f, 0.75f };
private int currentGear = 0;
public ParticleSystem ps1;
public ParticleSystem ps2;
[Header("Other")]
public float multiplierMax = 1.5f;
private float currentSteerAngle;
public float multiplier = 1f;
public Material snow;
public Image rpmFill;
public TextMeshProUGUI gear;
public Toggle toggle;
public TextMeshProUGUI SpeedTMP;
public GameObject dsda;
public Camera cam;
private float wearTimer = 0f;
[Header("radio")]
public Image RadioPanel;
public GameObject RadioGameObject;
public float fadeDuration = 1.0f;
public float visibleDuration = 3.0f;
private Coroutine activeFadeCoroutine;
[Header("Lights")]
public Light BLR;
public Light BLL;
public Light FLL;
public Light FLR;
public Light TBL;
public Light TBR;
public Light Blinker;
private float timer = 0.35f;
private float current;
private bool lblinking;
private bool rblinking;
public GameObject Crahsed;
[Header("Wheels")]
public List<GameObject> wheels = new List<GameObject>();
public TextMeshProUGUI speedText;
public Scrollbar rpmBar;
public AudioSource CameraPos;
public TextMeshProUGUI timeText;
public TextMeshProUGUI soundtrackName;
public Vector3 spawnPosition;
public TextMeshProUGUI soundTimeText;
public Rigidbody rb;
[Header("Delivery")]
public GameObject Point1;
public GameObject Point2;
public int point;
public bool task;
public GameObject DeliveryPanel;
public GameObject deliveryTrigger;
public TextMeshProUGUI DeliveryText;
public WheelCollider FL_WC, FR_WC, BL_WC, BR_WC;
public GameObject FLTIRE, FRTIRE, BLTIRE, BRTIRE;
public AudioSource BLTIRESCREECH;
public AudioSource BRTIRESCREECH;
private AudioSource engineAudio;
private float currentRPM = 0f;
private float doppler = 25f;
private float currentTime = 0f;
public VolumeProfile volume;
private AudioSource LightRlSource;
private MotionBlur motionBlur;
[Header("Drivetrain")]
public float finalDriveRatio = 3.5f;
public float wheelRadius = 0.53f; // wide
private float wcsnowfirction = 1f;
private float wcasphaltfriction = 1.2f;
private float wcmudfriction = 0.12f;
public int currentPoint;
public int cash;
public float taskTime;
private GlobalSaveData globalData;
[Header("Reverse")]
public float doubleTapWindow = 0.3f;
public float minSpeedForReverse = 1f;
private float lastSPressTime = -999f;
private int lastSFrameProcessed = -1;
private bool isReverse = false;
[Header("Clutch")]
public bool manualGearbox = true;
public bool canStall = true;
public KeyCode clutchKey = KeyCode.LeftShift;
public KeyCode shiftUpKey = KeyCode.X;
public KeyCode shiftDownKey = KeyCode.Z;
[Header("Эффект VTEC")]
[Range(0.5f, 0.9f)] public float vtecThreshold = 0.7f;
[Range(0f, 0.5f)] public float vtecDistortion = 0.28f;
private AudioDistortionFilter distortion;
public float engineInertia = 0.25f;
[Range(0f, 1f)] public float engineLoad; // Текущее усилие двигателя (0..1)
private AudioLowPassFilter lowPass;
private bool isClutch;
[Header("Gas")]
public float gasCapacity;
public float baseMass;
private float gasCurrency;
private float gasPrice = 1.92f;
private float startPrice;
public GameObject GasUI;
public TextMeshProUGUI gasCost;
public TextMeshProUGUI cmTMP;
public TextMeshProUGUI moneyTMP;
void ApplyMaterial(string materialId)
{
Renderer carRender = gameObject.GetComponent<Renderer>();
Material mat = Resources.Load<Material>("Materials/" + materialId);
if (mat != null)
carRender.material = mat;
else
Debug.LogWarning($"Материал {materialId} не найден");
}
void Start()
{
if(gasCurrency == 0){
gasCurrency = gasCapacity;
}
distortion = GetComponent<AudioDistortionFilter>();
isClutch = Input.GetKey(clutchKey);
globalData = SaveSystem.Load<GlobalSaveData>();
currentPoint = globalData.deliveryData.currentPoint;
cash = globalData.deliveryData.cash;
taskTime = globalData.deliveryData.taskTime;
ApplyMaterial(globalData.rsxSave.materialId);
Cursor.lockState = CursorLockMode.Locked;
Application.targetFrameRate = 60;
engineAudio = GetComponent<AudioSource>();
rb = GetComponent<Rigidbody>();
baseMass = rb.mass;
LightRlSource = FLR.GetComponent<AudioSource>();
if (volume.TryGet<MotionBlur>(out var mb))
motionBlur = mb;
UpdateTireWear();
Soundtrack();
currentTime = 0f;
}
string GetSurfaceTagUnderWheels()
{
WheelCollider[] wheels = { FL_WC, FR_WC, BL_WC, BR_WC };
foreach (var wheel in wheels)
{
if (wheel.GetGroundHit(out WheelHit hit))
{
return hit.collider.tag;
}
}
return "Asphalt";
}
private void TurnLights()
{
if (Input.GetKeyDown(KeyCode.Q) && TBL.enabled == false && lblinking == false)
{
rblinking = false;
lblinking = true;
TBR.enabled = false;
TBL.enabled = true;
TBL.GetComponent<AudioSource>().Play();
}
else if (Input.GetKeyDown(KeyCode.Q) && TBL.enabled == true && lblinking == true)
{
TBL.GetComponent<AudioSource>().Stop();
lblinking = false;
TBL.enabled = false;
}
if (Input.GetKeyDown(KeyCode.E) && TBR.enabled == false && rblinking == false)
{
lblinking = false;
rblinking = true;
TBR.enabled = true;
TBL.enabled = false;
TBR.GetComponent<AudioSource>().Play();
}
else if (Input.GetKeyDown(KeyCode.E) && TBR.enabled == true && rblinking == true)
{
TBR.GetComponent<AudioSource>().Stop();
rblinking = false;
TBR.enabled = false;
}
current += Time.deltaTime;
if (current > timer)
{
current = 0f;
if (lblinking)
{
TBL.enabled = !TBL.enabled;
}
else if (rblinking)
{
TBR.enabled = !TBR.enabled;
}
}
}
void LateUpdate()
{
TurnLights();
UpdateUI();
if (Input.GetKeyUp(KeyCode.M))
{
Soundtrack();
}
if (Input.GetKeyDown(KeyCode.V) && currentRPM == 0)
{
EngineStartup.Play();
Started = true;
engineAudio.Play();
}
// Cooldown таймер для ReverbZone (используем deltaTime, не fixedDeltaTime!)
if (ReverbZoneFloat > 0f)
ReverbZoneFloat -= Time.deltaTime;
}
void FixedUpdate()
{
// TaskUpdate();
HandleInput();
UpdateWheelCollidersPosition();
HandleGears();
string surfaceTag = GetSurfaceTagUnderWheels();
float targetFriction;
SetParticleSpeed(currentGear + 2);
switch (surfaceTag)
{
case "snow":
targetFriction = wcsnowfirction;
break;
case "Mud":
targetFriction = wcmudfriction;
break;
default:
targetFriction = wcasphaltfriction;
break;
}
if (surfaceTag == "snow")
{
if (!ps1.isPlaying) ps1.Play();
if (!ps2.isPlaying) ps2.Play();
}
else
{
if (ps1.isPlaying) ps1.Stop();
if (ps2.isPlaying) ps2.Stop();
}
ApplyFrictionToWheel(FL_WC, targetFriction * globalData.rsxSave.FLTire);
ApplyFrictionToWheel(FR_WC, targetFriction * globalData.rsxSave.FRTire);
ApplyFrictionToWheel(BL_WC, targetFriction * globalData.rsxSave.BLTire );
ApplyFrictionToWheel(BR_WC, targetFriction * globalData.rsxSave.BRTire);
wearTimer += Time.fixedDeltaTime;
if (wearTimer >= 6f)
{
UpdateTireWear();
wearTimer = 0f;
}
}
void ApplyFrictionToWheel(WheelCollider wheel, float baseStiffness)
{
float slipLoss = 0f;
if (wheel.GetGroundHit(out WheelHit hit))
{
float forwardSlip = Mathf.Abs(hit.forwardSlip);
slipLoss = Mathf.InverseLerp(0.35f, 1.0f, forwardSlip) * 0.6f;
}
WheelFrictionCurve forwardFriction = wheel.forwardFriction;
WheelFrictionCurve sidewaysFriction = wheel.sidewaysFriction;
forwardFriction.stiffness = baseStiffness;
sidewaysFriction.stiffness = baseStiffness * (1f - slipLoss);
wheel.forwardFriction = forwardFriction;
wheel.sidewaysFriction = sidewaysFriction;
}
void HandleGears()
{
isClutch = Input.GetKey(clutchKey);
if (isReverse == false && !isClutch){
if (currentRPM > rpmMax - 700 && currentGear < gearRatios.Length - 1)
{
currentRPM -= currentRPM / 2;
currentGear++;
}
else if (currentRPM < rpmMax / 2.5f && currentGear > 0)
{
currentRPM = rpmMax * 0.8f;
currentGear--;
//currentRPM = Mathf.Clamp(currentRPM * 1.3f, 0, rpmMax);
}
}
}
(float, float) GetWheelSidewaysLoad()
{
float load1 = 0f;
float load2 = 0f;
float load3 = 0f;
float load4 = 0f;
WheelHit hit;
if (BL_WC.GetGroundHit(out hit))
{
load1 = Mathf.Abs(hit.sidewaysSlip);
}
WheelHit hit2;
if (BR_WC.GetGroundHit(out hit2))
{
load2 = Mathf.Abs(hit2.sidewaysSlip);
}
WheelHit hit3;
if (FL_WC.GetGroundHit(out hit3))
{
load3 = Mathf.Abs(hit3.sidewaysSlip);
}
WheelHit hit4;
if (FR_WC.GetGroundHit(out hit4))
{
load4 = Mathf.Abs(hit4.sidewaysSlip);
}
return (load1, load2);
}
void UpdateTireWear()
{
float totalSlip = 0f;
int slipCount = 0;
if (BL_WC.GetGroundHit(out WheelHit hBL)) { totalSlip += Mathf.Abs(hBL.sidewaysSlip); slipCount++; }
if (BR_WC.GetGroundHit(out WheelHit hBR)) { totalSlip += Mathf.Abs(hBR.sidewaysSlip); slipCount++; }
if (FL_WC.GetGroundHit(out WheelHit hFL)) { totalSlip += Mathf.Abs(hFL.sidewaysSlip); slipCount++; }
if (FR_WC.GetGroundHit(out WheelHit hFR)) { totalSlip += Mathf.Abs(hFR.sidewaysSlip); slipCount++; }
if (slipCount == 0) return;
float avgSlip = totalSlip / slipCount;
var rsx = globalData.rsxSave;
float wear = avgSlip * 0.005f;
rsx.FLTire = Mathf.Max(0.2f, rsx.FLTire - wear);
rsx.FRTire = Mathf.Max(0.2f, rsx.FRTire - wear);
rsx.BLTire = Mathf.Max(0.2f, rsx.BLTire - wear);
rsx.BRTire = Mathf.Max(0.2f, rsx.BRTire - wear);
SaveSystem.Save(globalData);
}
float UpdateRPM(float vehicleSpeed, int gear, float radius, float finalDrive)
{
if (gear >= gearRatios.Length) gear = gearRatios.Length - 1;
float gearRatio = gearRatios[gear];
// Скорость в м/с, радиус в метрах
float wheelRPM = (vehicleSpeed * 60f) / (2f * Mathf.PI * radius);
float engineRPM = wheelRPM * gearRatio * finalDrive;
return engineRPM;
}
private void UpdateWheelCollidersPosition()
{
foreach (GameObject wheel in wheels)
{
Vector3 pos;
Quaternion rot;
WheelCollider WWC = wheel.transform.GetComponentInParent<WheelCollider>();
WWC.GetWorldPose(out pos, out rot);
wheel.transform.position = pos;
wheel.transform.rotation = rot;
}
}
private bool CanEngageReverse()
{
float speed = rb != null ? rb.linearVelocity.magnitude : 0f;
return speed < minSpeedForReverse;
}
void HandleInput()
{
rb.mass = baseMass + (gasCurrency * 0.71f);
if (Started != true)
{
return;
}
float totalRatio = gearRatios[currentGear] * finalDriveRatio;
float vertical = Input.GetAxis("Vertical");
float horizontal = Input.GetAxis("Horizontal");
float targetSteer = 33 * horizontal;
currentSteerAngle = Mathf.Lerp(currentSteerAngle, targetSteer, 4.2f * Time.fixedDeltaTime);
FL_WC.steerAngle = FR_WC.steerAngle = currentSteerAngle;
//rb.centerOfMass = new Vector3(Mathf.Clamp(horizontal,-0.1f,0.1f), 0.8f, Mathf.Clamp(vertical, -0.1f, 0.1f));
float speed = rb.linearVelocity.magnitude;
float wheelRPM = (speed * 60f) / (2f * Mathf.PI * wheelRadius);
float targetRPM;
if (Input.GetKey(clutchKey))
{
targetRPM = Mathf.Lerp(900f, rpmMax, Mathf.Clamp01(Mathf.Abs(vertical)));
}
else
{
float launchRPM = Mathf.Abs(vertical) * ((rpmMax * Time.fixedDeltaTime) / (wheelRadius * 4));
targetRPM = Mathf.Max(wheelRPM * totalRatio, launchRPM, 900f);
}
currentRPM = Mathf.Lerp(currentRPM, targetRPM, Time.fixedDeltaTime * 10f);
if (Input.GetKeyDown(KeyCode.S) && Time.frameCount != lastSFrameProcessed)
{
lastSFrameProcessed = Time.frameCount;
bool doubleTap = (Time.time - lastSPressTime) <= doubleTapWindow;
if (doubleTap && (isReverse || CanEngageReverse()))
{
isReverse = !isReverse;
lastSPressTime = -999f;
}
else
{
lastSPressTime = Time.time;
}
}
if (isReverse && Input.GetKeyDown(KeyCode.W))
isReverse = false;
if (isReverse && vertical > 0f)
vertical = 0f;
if (currentRPM > rpmMax)
{
currentRPM = rpmMax;
vertical = 0;
}
float rpmNorm = currentRPM / rpmMax;
float torqueCurve = Mathf.Lerp(0.55f, 1.0f, Mathf.Sin(rpmNorm * Mathf.PI * 0.85f));
float engineTorque = motorTorque * torqueCurve;
float throttleEffort = Mathf.Abs(vertical);
float resistanceFactor = 1.25f - (rpmNorm * 0.65f);
float engineEffort = isClutch ? (throttleEffort * 0.25f) : Mathf.Clamp01(throttleEffort * resistanceFactor);
// float totalRatio = gearRatios[currentGear] * finalDriveRatio;
if(vertical < 0f && !isReverse){
vertical = 0f;
}
float mt = engineTorque * totalRatio * vertical;
if (Input.GetKey(clutchKey)){
mt = 0;
}
FL_WC.motorTorque = FR_WC.motorTorque = mt;
string surfaceTag = GetSurfaceTagUnderWheels();
if (surfaceTag != "snow")
{
engineAudio.pitch = Mathf.Lerp(0.9f, 1.2f, currentRPM / rpmMax);
}
else
{
engineAudio.pitch = Mathf.Lerp(1f, 2.1f, currentRPM / rpmMax);
}
engineAudio.volume = Mathf.Clamp(currentRPM / rpmMax, 0.005f, 0.02f) * EngineBasicVolumeValue.value;
distortion.distortionLevel = Mathf.Clamp(currentRPM / rpmMax, 0.05f, 0.01f) * engineEffort;
speedText.text = Mathf.RoundToInt(speed * 3.6f).ToString() + " км/ч";
rpmBar.size = currentRPM / rpmMax;
if (motionBlur)
{
float currentWheelRPM = Mathf.Abs(rb.linearVelocity.magnitude);
float targetNormalizedRPM = Mathf.Clamp01(currentWheelRPM / rpmMax);
float maxSafeBlur = 5f;
float targetIntensity = targetNormalizedRPM * maxSafeBlur;
float currentBlur = motionBlur.intensity.value;
motionBlur.intensity.value = Mathf.Lerp(currentBlur, targetIntensity, Time.deltaTime * 5f);
motionBlur.intensity.overrideState = true;
}
float gearFactor = Mathf.Lerp(0.6f, 1.4f, (float)currentGear / (gearRatios.Length - 1));
float targetVolume = (currentRPM / rpmMax) * gearFactor * CameraSoundtrackBaseValue.value;
CameraPos.volume = Mathf.Clamp(targetVolume, 0f, 0.7f);
speedText.text = currentRPM.ToString() + "/" + currentGear.ToString();
rpmBar.size = currentRPM / rpmMax;
bool sHeld = Input.GetKey(KeyCode.S);
float maxFuelConsumption = 0.05f;
float idleConsumption = 0.002f;
float fuelUsed = (idleConsumption + engineEffort * maxFuelConsumption) * Time.fixedDeltaTime;
if (!GasUI.active){
gasCurrency = Mathf.Max(0f, gasCurrency - fuelUsed);
}
Debug.Log(gasCurrency);
globalData.rsxSave.rsxGasCurrency = gasCurrency;
bool isHandbrake = Input.GetKey(KeyCode.Space);
float brake = 0f;
if (!isClutch && Mathf.Approximately(vertical, 0f) && currentRPM > 1000f)
{
mt = -120f * rpmNorm * (isReverse ? -1f : 1f);
}
if (isReverse)
{
BLR.intensity = BLL.intensity = 0.35f;
rpmMax = 4000f;
BLR.color = BLL.color = Color.white;
}
else if (sHeld && currentRPM > 200)
{
brake = brakeTorque;
BLR.intensity = BLL.intensity = 0.35f;
BLR.color = BLL.color = Color.red;
if (Blinker) { Blinker.enabled = true; Blinker.color = Color.red; }
}
else
{
rpmMax = 7000f;
BLR.intensity = BLL.intensity = 0.2f;
BLR.color = BLL.color = Color.red;
if (Blinker) Blinker.enabled = false;
}
FL_WC.brakeTorque = FR_WC.brakeTorque = brake * 1.2f;
BL_WC.brakeTorque = BR_WC.brakeTorque = brake;
FL_WC.brakeTorque = FR_WC.brakeTorque = brake * 1.2f;
BL_WC.brakeTorque = BR_WC.brakeTorque = brake;
if (Input.GetKeyDown(KeyCode.L))
{
bool lightsOn = !FLR.enabled;
FLL.enabled = FLR.enabled = lightsOn;
}
if (Input.GetKeyDown(KeyCode.R))
{
Restart();
}
(float leftLoad, float rightLoad) = GetWheelSidewaysLoad();
BLTIRESCREECH.volume = (leftLoad * wheelRadius) / 2;
BRTIRESCREECH.volume = (rightLoad * wheelRadius) / 2;
}
// Кривые трения
private readonly WheelFrictionCurve normalFriction = new WheelFrictionCurve
{
extremumSlip = 0.4f,
extremumValue = 1.2f,
asymptoteSlip = 0.8f,
asymptoteValue = 1.0f,
stiffness = 1f
};
private readonly WheelFrictionCurve driftFriction = new WheelFrictionCurve
{
extremumSlip = 0.3f,
extremumValue = 1.0f,
asymptoteSlip = 0.6f,
asymptoteValue = 0.6f,
stiffness = 0.5f // ↓ сцепление = дрифт!
};
void SetWheelFriction(WheelFrictionCurve friction)
{
FL_WC.sidewaysFriction = FR_WC.sidewaysFriction = BL_WC.sidewaysFriction = BR_WC.sidewaysFriction = friction;
FL_WC.forwardFriction = FR_WC.forwardFriction = BL_WC.forwardFriction = BR_WC.forwardFriction = friction;
}
void UpdateUI()
{
// RPM прогресс
rpmBar.size = Mathf.Clamp01(currentRPM / rpmMax);
rpmFill.fillAmount =( currentRPM / 8000f) * 0.708f;
gear.text = $"{currentGear + 1}";
float rpmOverLimit = currentRPM - (rpmMax - 1200f);
float redIntensity = Mathf.Clamp01(rpmOverLimit / 1200f);
Color normalColor = Color.white;
Color dangerColor = Color.red;
gear.color = Color.Lerp(normalColor, dangerColor, redIntensity);
SpeedTMP.text = $"{Mathf.Round(rb.linearVelocity.magnitude * 2.6f)}";
// Звук саундтрека
if (CameraPos.clip != null)
{
soundTimeText.text = $"{CameraPos.time:F0}/{CameraPos.clip.length:F0}";
}///
// GlobalSaveData globalData = SaveSystem.Load<GlobalSaveData>();
currentPoint = globalData.deliveryData.currentPoint;
cash = globalData.deliveryData.cash;
taskTime = globalData.deliveryData.taskTime;
float starttasktime = globalData.deliveryData.starttasktime;
Timer.volume = (starttasktime - taskTime) / 100;
if (GasUI.active)
{
if ((Input.GetKey(KeyCode.Return) || Input.GetKey(KeyCode.KeypadEnter)) && gasCurrency < gasCapacity)
{
float refuelSpeed = 10f;
float litersToAdd = refuelSpeed * Time.deltaTime;
if (gasCurrency + litersToAdd > gasCapacity)
{
litersToAdd = gasCapacity - gasCurrency;
}
float frameCost = litersToAdd * gasPrice;
if (cash >= pendingCost + frameCost)
{
gasCurrency += litersToAdd;
startPrice += frameCost;
pendingCost += frameCost;
if (pendingCost >= 1f)
{
int wholeMoney = Mathf.FloorToInt(pendingCost);
globalData.deliveryData.cash -= wholeMoney;
cash -= wholeMoney;
pendingCost -= wholeMoney;
}
}
}
cmTMP.text = $"{gasCurrency:F0} / {gasCapacity}";
gasCost.text = $"${startPrice} ({gasPrice}/1L)";
}
moneyTMP.text = $"${cash}";
if (currentPoint > 0)
{
int maxtime = currentPoint * 100;
taskTime -= Time.fixedDeltaTime;
DeliveryText.text = $"{Mathf.CeilToInt(taskTime)} / {maxtime}";
}
saveTimer += Time.deltaTime;
if (saveTimer >= 5f) {
saveTimer = 0f;
globalData.deliveryData.taskTime = taskTime;
globalData.deliveryData.currentPoint = currentPoint;
globalData.deliveryData.cash = cash;
SaveSystem.Save(globalData);
}
}
public void SetParticleSpeed(float newSpeed)
{
var main = ps1.main;
main.startSpeed = newSpeed;
var main2 = ps2.main
; main2.startSpeed = newSpeed;
}
public void Soundtrack()
{
AudioClip[] clips = toggle.isOn ? GameAssets.AudioClips2 : GameAssets.AudioClips;
if (clips == null || clips.Length == 0)
{
Debug.LogWarning("No audio clips available");
return;
}
AudioClip newClip = clips[UnityEngine.Random.Range(0, clips.Length)];
CameraPos.clip = newClip;
CameraPos.Play();
soundtrackName.text = newClip.name;
if (activeFadeCoroutine != null)
{
StopCoroutine(activeFadeCoroutine);
}
activeFadeCoroutine = StartCoroutine(FadeRadioPanel());
}
private IEnumerator FadeRadioPanel()
{
RadioGameObject.SetActive(true);
Color color = RadioPanel.color;
float elapsedTime = 0f;
while (elapsedTime < fadeDuration)
{
elapsedTime += Time.deltaTime;
color.a = Mathf.Lerp(0f, 0.8f, elapsedTime / fadeDuration); // Из 0 в 1
RadioPanel.color = color;
yield return null;
}
color.a = 0.8f;
RadioPanel.color = color;
yield return new WaitForSeconds(visibleDuration);
elapsedTime = 0f;
while (elapsedTime < fadeDuration)
{
elapsedTime += Time.deltaTime;
color.a = Mathf.Lerp(0.8f, 0f, elapsedTime / fadeDuration); // Из 1 в 0
RadioPanel.color = color;
yield return null;
}
color.a = 0f;
RadioPanel.color = color;
activeFadeCoroutine = null;
RadioGameObject.SetActive(false);
}
public void Restart()
{
engineAudio.pitch = 1.15f;
transform.rotation = Quaternion.identity;
currentRPM = 0;
multiplier = 1.1f;
currentTime = 0f;
Cursor.lockState = CursorLockMode.Locked;
}
// Добавьте эти счётчики в поля класса (вверху скрипта)
private int gasCollidersCount = 0;
private int reverbCollidersCount = 0;
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Delivery"))
{
DeliveryPanel.SetActive(true);
Cursor.lockState = CursorLockMode.None;
}
else if (other.CompareTag("Delivend") && currentPoint > 0)
{
GlobalSaveData globalData = SaveSystem.Load<GlobalSaveData>();
currentPoint = globalData.deliveryData.currentPoint;
cash = globalData.deliveryData.cash;
int reward = (currentPoint == 1) ? 15 : 18;
cash += reward;
currentPoint = 0;
other.gameObject.SetActive(false);
if (BL_WC.TryGetComponent(out AudioSource deliverSound))
deliverSound.Play();
deliveryTrigger.SetActive(true);
DeliveryText.text = "None";
taskTime = 0;
globalData.deliveryData.currentPoint = currentPoint;
globalData.deliveryData.cash = cash;
globalData.deliveryData.starttasktime = 0f;
globalData.deliveryData.taskTime = taskTime;
SaveSystem.Save(globalData);
}
else if (other.CompareTag("Garage"))
{
Cursor.lockState = CursorLockMode.None;
SceneManager.LoadScene("garage");
}
else if (other.CompareTag("Finish"))
{
SceneManager.LoadScene("машонки");
}
else if (other.CompareTag("Reverbzone"))
{
reverbCollidersCount++;
if (reverbCollidersCount == 1)
{
engineAudio.GetComponent<AudioReverbFilter>().enabled = !engineAudio.GetComponent<AudioReverbFilter>().enabled;
CameraPos.GetComponent<AudioReverbFilter>().enabled = !CameraPos.GetComponent<AudioReverbFilter>().enabled;
}
}
else if (other.CompareTag("Gas"))
{
gasCollidersCount++;
if (gasCollidersCount == 1)
{
startPrice = 0f;
GasUI.SetActive(true);
SetReverb(true);
}
}
}
private void OnTriggerExit(Collider other)
{
if (other.CompareTag("Gas"))
{
gasCollidersCount--;
if (gasCollidersCount <= 0)
{
gasCollidersCount = 0;
startPrice = 0f;
GasUI.SetActive(false);
SetReverb(false);
}
}
}
private void SetReverb(bool state)
{
engineAudio.GetComponent<AudioReverbFilter>().enabled = state;
CameraPos.GetComponent<AudioReverbFilter>().enabled = state;
}
}27,344 chars · codepastes.com