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!
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!