You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
175 lines
4.9 KiB
C#
175 lines
4.9 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class NOSController : MonoBehaviour
|
|
{
|
|
[SerializeField] private float _currentNOS = 0f;
|
|
[SerializeField] private float _chargeSpeed = 1f;
|
|
[SerializeField] private float _depletionSpeed = 1f;
|
|
[SerializeField] private float _boostAcceleration = 40f;
|
|
[SerializeField] private float _audioVolume = 0.5f;
|
|
[SerializeField] private AudioSource _boostAudio = null;
|
|
|
|
public bool _isBoosting = false;
|
|
private VehicleController _vehicleHandler = null;
|
|
private MotionBlur _cameraMotionBlur;
|
|
public float NOSRatio => _currentNOS / 100f;
|
|
public Image _boostBarFill;
|
|
|
|
private void Awake()
|
|
{
|
|
_vehicleHandler = GetComponent<VehicleController>();
|
|
_cameraMotionBlur = Camera.main.GetComponent<MotionBlur>();
|
|
|
|
if (_boostAudio != null)
|
|
{
|
|
_boostAudio.playOnAwake = false;
|
|
_boostAudio.loop = true;
|
|
_boostAudio.volume = _audioVolume;
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (_vehicleHandler.AIControlled) return;
|
|
|
|
if (!_isBoosting)
|
|
{
|
|
if (Mathf.Abs(_vehicleHandler.LocalVelocity.x) > 10f && _currentNOS < 100f)
|
|
{
|
|
_currentNOS += Time.deltaTime * (_chargeSpeed * _vehicleHandler.LocalVelocity.z / 30f);
|
|
_boostBarFill.fillAmount = _currentNOS / 100f;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (_vehicleHandler.InputsActive)
|
|
{
|
|
_currentNOS -= Time.deltaTime * _depletionSpeed;
|
|
_boostBarFill.fillAmount = _currentNOS / 100f;
|
|
}
|
|
|
|
if (_currentNOS <= 0f)
|
|
_isBoosting = false;
|
|
}
|
|
|
|
ManageBoost();
|
|
}
|
|
|
|
private void ManageBoost()
|
|
{
|
|
if (_isBoosting && _vehicleHandler.InputsActive && _vehicleHandler.Running)
|
|
{
|
|
if (_cameraMotionBlur != null)
|
|
_cameraMotionBlur.enabled = true;
|
|
}
|
|
else
|
|
{
|
|
if (_cameraMotionBlur != null)
|
|
_cameraMotionBlur.enabled = false;
|
|
|
|
_vehicleHandler.ActivateNOS(false);
|
|
}
|
|
}
|
|
|
|
public void ActivateNOS()
|
|
{
|
|
if (_isBoosting || _currentNOS <= 0f) return;
|
|
_isBoosting = true;
|
|
_vehicleHandler.ActivateNOS(_isBoosting, _boostAcceleration);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//using UnityEngine;
|
|
//using UnityEngine.UI;
|
|
|
|
//public class NOSController : MonoBehaviour
|
|
//{
|
|
// [SerializeField] float _nosAmount = 0f;
|
|
// [SerializeField] float _nosFillRate = 1f;
|
|
// [SerializeField] float _nosUseRate = 1f;
|
|
// [SerializeField] float _nosAccelarationAddition = 40f;
|
|
// [SerializeField] float _nosVolume = 0.5f;
|
|
// [SerializeField] AudioSource _nosSource = null;
|
|
|
|
// public bool _useNOS = false;
|
|
// private VehicleController _controller = null;
|
|
// private MotionBlur fastMotionBlur;
|
|
// public float NOSFillAmount => _nosAmount / 100f;
|
|
// public Image nosFillImg;
|
|
// private void Awake()
|
|
// {
|
|
// _controller = GetComponent<VehicleController>();
|
|
// fastMotionBlur = Camera.main.GetComponent<MotionBlur>();
|
|
|
|
// if (_nosSource != null)
|
|
// {
|
|
// _nosSource.playOnAwake = false;
|
|
// _nosSource.loop = true;
|
|
// _nosSource.volume = _nosVolume;
|
|
// }
|
|
// }
|
|
|
|
// private void Update()
|
|
// {
|
|
// if (_controller.IsAI) return;
|
|
|
|
// if (!_useNOS)
|
|
// {
|
|
// if (Mathf.Abs(_controller.CarVelocity.x) > 10f && _nosAmount < 100f)
|
|
// {
|
|
// _nosAmount += Time.deltaTime * (_nosFillRate * _controller.CarVelocity.z / 30f);
|
|
// nosFillImg.fillAmount = _nosAmount / 100f;
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// if (_controller.IsTouchDown)
|
|
// {
|
|
// _nosAmount -= Time.deltaTime * _nosUseRate;
|
|
// nosFillImg.fillAmount = _nosAmount / 100f;
|
|
// }
|
|
|
|
// if (_nosAmount <= 0f)
|
|
// _useNOS = false;
|
|
// }
|
|
|
|
// HandleNOS();
|
|
// }
|
|
|
|
// private void HandleNOS()
|
|
// {
|
|
// if (_useNOS && _controller.IsTouchDown && _controller.CanRun)
|
|
// {
|
|
// if (fastMotionBlur != null)
|
|
// fastMotionBlur.enabled = true;
|
|
// //if (!_nosSource.isPlaying)
|
|
// //{
|
|
// // _nosSource.Play();
|
|
// // _controller.UseNOS(_useNOS, _nosAccelarationAddition);
|
|
// //}
|
|
// }
|
|
// else
|
|
// {
|
|
// if (fastMotionBlur != null)
|
|
// fastMotionBlur.enabled = false;
|
|
|
|
// _controller.UseNOS(false);
|
|
// //if (_nosSource.isPlaying)
|
|
// //{
|
|
// // _nosSource.Stop();
|
|
// // _controller.UseNOS(false);
|
|
// //}
|
|
// }
|
|
// }
|
|
|
|
// public void ActivateNOS()
|
|
// {
|
|
// if (_useNOS || _nosAmount <= 0f) return;
|
|
// _useNOS = true;
|
|
// _controller.UseNOS(_useNOS, _nosAccelarationAddition);
|
|
// }
|
|
//}
|