There’s an issue where both the thrusters enable while pressing D
Rigidbody rb;
AudioSource audioSource;
[SerializeField] float mainThrust = 1000f;
[SerializeField] float rotationSpeed = 0f;
[SerializeField] AudioClip mainEngine;
[SerializeField]ParticleSystem thrusterParticle;
[SerializeField]ParticleSystem leftThrusterParticle;
[SerializeField]ParticleSystem rightThrusterParticle;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
audioSource = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update()
{
ProcessThrust();
ProcessRotation();
}
void ProcessThrust()
{
if (Input.GetKey(KeyCode.W))
{
rb.AddRelativeForce(Vector3.up *mainThrust*Time.deltaTime);
if (!audioSource.isPlaying)
{
audioSource.PlayOneShot(mainEngine);
}
if(!thrusterParticle.isPlaying)
{
thrusterParticle.Play();
}
}
else
{
audioSource.Stop();
thrusterParticle.Stop();
}
}
void ProcessRotation()
{
if (!rightThrusterParticle.isPlaying)
{
rightThrusterParticle.Play();
}
{
rb.freezeRotation = true;
}
if (Input.GetKey(KeyCode.A))
{
transform.Rotate(Vector3.forward*rotationSpeed*Time.deltaTime);
}
else if (Input.GetKey(KeyCode.D))
{
transform.Rotate(-Vector3.forward*rotationSpeed*Time.deltaTime);
rb.freezeRotation = false;
if (!leftThrusterParticle.isPlaying)
{
leftThrusterParticle.Play();
}
}
else
{
rightThrusterParticle.Stop();
leftThrusterParticle.Stop();
}
}
}