|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class SkidMarks : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
[SerializeField] private GameObject _driftEffect;
|
|
|
|
|
private VehicleController _attachedController = null;
|
|
|
|
|
private ParticleSystem _smokeEffect = null;
|
|
|
|
|
private TrailRenderer _tireTrail = null;
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
|
_attachedController = GetComponentInParent<VehicleController>();
|
|
|
|
|
_smokeEffect = GetComponent<ParticleSystem>();
|
|
|
|
|
_tireTrail = GetComponent<TrailRenderer>();
|
|
|
|
|
_tireTrail.emitting = false;
|
|
|
|
|
_tireTrail.startWidth = _attachedController.SkidWidth;
|
|
|
|
|
_tireTrail.time = _attachedController.SkidDuration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
|
{
|
|
|
|
|
_tireTrail.enabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
|
{
|
|
|
|
|
_tireTrail.enabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FixedUpdate()
|
|
|
|
|
{
|
|
|
|
|
if (_attachedController.Running)
|
|
|
|
|
{
|
|
|
|
|
if (_attachedController.Grounded)
|
|
|
|
|
{
|
|
|
|
|
//_tireTrail.emitting = Mathf.Abs(_attachedController.LocalVelocity.x) > 10f;
|
|
|
|
|
_tireTrail.emitting = Mathf.Abs(_attachedController.LocalVelocity.x) > 25f && _attachedController.CurrentSpeed > 70f;
|
|
|
|
|
//_tireTrail.emitting =
|
|
|
|
|
//Mathf.Abs(_attachedController.LocalVelocity.x) > 5f &&
|
|
|
|
|
//_attachedController.CurrentSpeed > 20f;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_tireTrail.emitting = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_tireTrail.emitting)
|
|
|
|
|
{
|
|
|
|
|
if (_driftEffect != null)
|
|
|
|
|
_driftEffect.SetActive(true);
|
|
|
|
|
if (_smokeEffect != null)
|
|
|
|
|
_smokeEffect.Play();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (_driftEffect != null)
|
|
|
|
|
_driftEffect.SetActive(false);
|
|
|
|
|
if (_smokeEffect != null)
|
|
|
|
|
_smokeEffect.Stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_tireTrail.emitting = false;
|
|
|
|
|
if (_smokeEffect != null)
|
|
|
|
|
_smokeEffect.Stop();
|
|
|
|
|
if (_driftEffect != null)
|
|
|
|
|
_driftEffect.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|