Audio Issue: Plays in reverse order or not at all

Been looking this up now for awhile, finally today i’m stuck on this script, i’m still new walking through tutorials and what not while building something I can tear apart and play with to understand things better, most problems I’ve been able to work at and fix myself.
Also not an Optimal script, still learning! :wink:

using UnityEngine;
using System.Collections;

public class ShipMovement : MonoBehaviour {

public int turnspeed;
public int maxspeed;
public float speed;
public float targetspeed;
public float currentspeed;
public Rigidbody currentship;
private Vector3 movement;
public Object errorObject;
public MeshRenderer engines;
public AudioSource engineAudio;

void Update()
{

    currentship = GetComponent<Rigidbody>();
    targetspeed = Mathf.Round(speed * maxspeed);
    currentspeed = Mathf.Round(GetComponent<Rigidbody>().velocity.z);

    engines.enabled = false;
  //  engineAudio.Stop();

    float roll = Input.GetAxis("Horizontal"); 
    float pitch = Input.GetAxis("Vertical"); 
    float yaw = Input.GetAxis("Roll"); 
    float translate = Input.GetAxis("Translate"); 
    //  float throttle = Input.GetAxis("Throttle"); 

    if (Input.GetKey("r"))
    {
        currentship.AddForce(transform.forward * speed * 5f);
        engines.enabled = true;
        if (Input.GetKeyDown("r"))
        {
            if (engineAudio == true)
            {
                engineAudio.Play();
            }
            else
            {
                engineAudio.Stop();
            }
        }
    }
    if (Input.GetKey("f"))
    {
        currentship.AddForce(-transform.forward * speed * 5f);
        
    }
    if (Input.GetKey("t"))

    {
        currentship.AddForce(transform.up * speed * 1);
    }
    if (Input.GetKey("g"))
    {
        currentship.AddForce(transform.up * -speed * 1);
    }

    GetComponent<Rigidbody>().AddRelativeTorque(pitch * turnspeed * Time.deltaTime, yaw * turnspeed * Time.deltaTime, -roll * turnspeed * Time.deltaTime);
}

}

now what’s happening is the audio on the thrusters are firing in reverse order, when i thrust forward the audio should play when released it should stop the audio, it does not, it starts the audio after i release the thrust.

If I change any statements below it say True to False or change stop and play around the audio just won’t play period.

Any help/direction where to look would be great. Other audio issue’s i’ve researched have had solutions like creating a seperate object for sound or few other things that may/may not relate to me, but I just cant figure this one out!

Thanks!

Fixed my problem, took a break and walked away from desk head smashing and another hour and playing around, I did end up giving it a totally new object, figure’d what the hell. After it was still not working. Changed code to look like this:

using UnityEngine;
using System.Collections;


public class ShipMovement : MonoBehaviour {

    
    public int turnspeed;
    public int maxspeed;
    public float speed;
    public float targetspeed;
    public float currentspeed;
    public Rigidbody currentship;
    private Vector3 movement;
    public Object errorObject;
    public MeshRenderer engines;
    public AudioSource engineAudio;


    void Update()
    {

        currentship = GetComponent<Rigidbody>();
        targetspeed = Mathf.Round(speed * maxspeed);
        currentspeed = Mathf.Round(GetComponent<Rigidbody>().velocity.z);

        engines.enabled = false;
       // engineAudio.enabled = false;


        float roll = Input.GetAxis("Horizontal"); //A en D
        float pitch = Input.GetAxis("Vertical"); //W en S
        float yaw = Input.GetAxis("Roll"); //Q en E
        float translate = Input.GetAxis("Translate"); // G T
        //  float throttle = Input.GetAxis("Throttle"); //R en F

        if (Input.GetKey("r"))
        {
            currentship.AddForce(transform.forward * speed * 5f);
            engines.enabled = true;
            EngineAudio();
        }

        else
        {
            engineAudio.enabled = false;
        
        }
        if (Input.GetKey("f"))
        {
            currentship.AddForce(-transform.forward * speed * 5f);
            
        }
        if (Input.GetKey("t"))

        {
            currentship.AddForce(transform.up * speed * 1);
        }
        if (Input.GetKey("g"))
        {
            currentship.AddForce(transform.up * -speed * 1);
        }

        GetComponent<Rigidbody>().AddRelativeTorque(pitch * turnspeed * Time.deltaTime, yaw * turnspeed * Time.deltaTime, -roll * turnspeed * Time.deltaTime);
    }

    void EngineAudio()
    {
        engineAudio.playOnAwake = true;
        engineAudio.loop = true;
        engineAudio.enabled = true;
    }
        


}

Hope this may help people later, i put a second void at the bottom to help call it aswell

Thanks for any lookers before! also if you have any further tips on it, I’m still willing to learn/listen! feel free to put in your opinion!