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.
94 lines
2.7 KiB
C#
94 lines
2.7 KiB
C#
using Mirror;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class NOSController : NetworkBehaviour
|
|
{
|
|
[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 NetworkIdentity identity;
|
|
|
|
public override void OnStartLocalPlayer()
|
|
{
|
|
Debug.Log("isLocalPlayer");
|
|
|
|
_boostBarFill = GameUIManager.Instance.boostBarFill;
|
|
GameUIManager.Instance.boostButton.onClick.RemoveAllListeners();
|
|
GameUIManager.Instance.boostButton.onClick.AddListener(ActivateNOS);
|
|
}
|
|
|
|
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 (!isLocalPlayer || _vehicleHandler.AIControlled)
|
|
return;
|
|
|
|
Debug.Log("NosController Local");
|
|
|
|
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);
|
|
}
|
|
} |