PLEASE Help me with this Audio Issue

How can i get it so that when i have vertical and horizontal movement i play an audio clip.

I have this as my script but the audio is distorted and messed up. What’s wrong?

var walkAudio : AudioClip;
var isMoving : boolean = false;




function Update() {

    if (Input.GetAxis("Horizontal") || Input.GetAxis("Vertical") )
    
    isMoving = true;
	audio.PlayOneShot(walkAudio);
}

That code doesn't distort audio. Have you checked the import settings on the audio file? Is your bitrate correct?

1 Answer

1

I suggest you put all your audio under one parent group,
and then you just call the sound you need.

gameObject.Find(“YourAudio”).audio.Play();

ughh what do you meaan.. like have a parent game object then few game objects as children in it with their own sounds??

yes, each with their own audio source, or else you will end up with audio all over the place. It's fine for small projects only.

it does not work.....

create an empty gameObject, put an audio source on it. drag your audio file in the audio source. Then call it: gameObject.Find("YourAudio").audio.Play();

does not do anything