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.
67 lines
1.8 KiB
C#
67 lines
1.8 KiB
C#
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;
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
} |