Thanks guys so much for your feedback and assistance with the editor. As it turns out however, between the poor quality of my speakers and the low pitch of the clip, it was very hard to hear if it was playing properly.
Also I may have instanciated the sourceAudio.Stop incorrectly.
[SPACE] adds force to Vector3.up
[A] adds force to Vector3.left
[D] adds force to Vector3.right
All these seem to be functional for the ship but not for the audio.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Rocket : MonoBehaviour {
Rigidbody rigidBody;
AudioSource audioSource;
// Start is called before the first frame update
void Start() {
rigidBody = GetComponent<Rigidbody>();
audioSource = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update() {
ProcessInput();
}
private void ProcessInput()
{
if (Input.GetKey(KeyCode.Space))
{
rigidBody.AddRelativeForce(Vector3.up);
if (!audioSource.isPlaying)
{
audioSource.Play();
}
}
if (Input.GetKey(KeyCode.A))
{
transform.Rotate(Vector3.forward);
if (!audioSource.isPlaying)
{
audioSource.Play();
}
}
else if (Input.GetKey(KeyCode.D))
{
transform.Rotate(-Vector3.forward);
if (!audioSource.isPlaying)
{
audioSource.Play();
}
}
}
}
Test your game. Can you hear the sound? Also check in the game window whether there is a “Mute Audio” button. I usually have my audio muted when working in Unity. Maybe your audio is muted, too.
If not, call audioSource.Play() in the Start() method for testing purposes. Do not press any key. Can you hear the sound now?