/* * if (_prevEngineTorque > 0 && WCRL.motorTorque == 0) * { * //EngineAudioSource.Stop(); * //ClutchAudioSource.Play(); * ClutchStartTime = Time.time; * } * //Idle * if (_prevEngineTorque == 0 && WCRL.motorTorque == 0 && IdleAudioSource.isPlaying == false && Time.time > ClutchStartTime + 1f && EngineAudioSource.isPlaying == false) * { * EngineAudioSource.Play(); * } * if (Mathf.Abs(WCRL.motorTorque) < 1000000) * { * ClutchAudioSource.Stop(); * //IdleAudioSource.Stop(); * float _pitch; * if (EngineAudioSource.isPlaying == true) { * _pitch = Mathf.Clamp(WCRL.rpm / 800f,0.5f,1f); * EngineAudioSource.pitch = _pitch;// * 0.1f + EngineAudioSource.pitch * 0.9f; * float StartTIme = UnityEngine.Random.Range(0, EngineAudioSource.clip.length - 1f); * EngineAudioSource.time = StartTIme; * float EndTIme; * if (EngineAudioSource.pitch < 0) EndTIme = UnityEngine.Random.Range(StartTIme, 0); * else EndTIme = UnityEngine.Random.Range(StartTIme, EngineAudioSource.clip.length); * EngineAudioSource.Play(); * EngineAudioSource.SetScheduledEndTime(AudioSettings.dspTime + EndTIme); } * /* * if (Wheelrpm < 300) * { * rpm = -Wheelrpm; * _pitch = rpm / 600 - 0.5f; * Gear = 1; * } * else * { * rpm = -(Wheelrpm - 300) % 300; * Gear = (int)Wheelrpm / 300 + 1; * _pitch = (rpm / 600 - 0.5f); * * } * // EngineAudioSource.pitch = _pitch*1.5f; * * } * CoughAudioSource.mute = (WCRL.motorTorque != 0); * _prevEngineTorque = WCRL.motorTorque; * _prevRPM = WCRL.rpm; */ public override void StartEngine() { IdleAudioSource.mute = false; RevAudioSource.mute = false; AccelAudioSource.mute = false; DecelAudioSource.mute = false; IdleAudioSource.Play(); }
void Update() { if (Gps != null) { if (_gpsTimer == 0) { Gps.UpdateSegIdx(); _gpsTimer = 2; } _gpsTimer--; } //Engine Sound if (WCRL.motorTorque > 0 && WCRL.brakeTorque == 0) { if (IdleAudioSource.isPlaying || DecelAudioSource.isPlaying) { IdleAudioSource.Stop(); DecelAudioSource.Stop(); RevAudioSource.Play(); RevStartTime = Time.time; } if (RevStartTime != 0 && Time.time > RevStartTime + 1.5f) { AccelAudioSource.timeSamples = UnityEngine.Random.Range(0, AccelAudioSource.clip.samples); AccelAudioSource.Play(); RevStartTime = 0; } } else { if (AccelAudioSource.isPlaying || RevAudioSource.isPlaying) { AccelAudioSource.Stop(); RevAudioSource.Stop(); DecelAudioSource.Play(); DecelStartTime = Time.time; } if (DecelStartTime != 0 && Time.time > DecelStartTime + 3f) { IdleAudioSource.Play(); DecelStartTime = 0; } } _prevEngineTorque = WCRL.motorTorque; }