The short answer
Import the exported sound into the Unity project, assign it to an AudioSource in the Inspector, and call PlayOneShot from the gameplay event. Keep the AudioSource settings in the Editor so designers can tune volume, pitch and spatial blend without changing code.
A reliable way to start
- Make a focused assetGenerate one game event at a time. A sword impact, a menu confirmation and an ambience loop are separate assets with different timing.
- Set import and AudioSource optionsDrag the WAV or OGG into Assets, then add an AudioSource to the scene or prefab. Use the Inspector to set the clip and choose 2D or 3D playback.
- Trigger the existing sourceReference the configured AudioSource from the component that owns the action. Use PlayOneShot for compact effects so the configured source stays reusable.
Prompt examples
Use these as a starting point, then change the source, action, timing and perspective to fit your scene.
short Unity game button confirmation, precise tactile click with a small warm upward tone, dry compact UI feedback
steel sword striking a wooden shield once, clear wood body and brief metal edge, tight fantasy combat impact
small health pickup, gentle warm rising chime with soft energy sparkle, short readable game feedback
quiet underground cave ambience, distant water movement and sparse drips, no music or foreground actions, seamless loop
What makes the result more useful
- Set AudioSource volume and spatial settings in the Unity Inspector so the sound remains tunable without a code change.
- Use PlayOneShot for UI and transient effects that may overlap; test overlap in the real game loop.
- Create a small variation group for common actions instead of replaying a single footstep or pickup.
Add the sound to your game
Play a configured one-shot
Add an AudioSource and assign the clip in the Inspector. Attach this component to the object that owns the interaction.
using UnityEngine;
public sealed class UiSoundPlayer : MonoBehaviour
{
[SerializeField] private AudioSource confirmationSource;
[SerializeField] private AudioClip confirmationClip;
public void Confirm()
{
confirmationSource.PlayOneShot(confirmationClip);
}
}Choose a different footstep each time
Assign all clips in the Inspector. The code only chooses a clip; the AudioSource still controls the mix and 3D settings.
[SerializeField] private AudioSource footstepSource;
[SerializeField] private AudioClip[] footstepClips;
public void PlayFootstep()
{
var clip = footstepClips[Random.Range(0, footstepClips.Length)];
footstepSource.PlayOneShot(clip);
}Frequently asked questions
Should a Unity UI sound be 2D or 3D?
UI feedback is usually 2D. Sounds that belong to an object in the world can use 3D spatial settings, then be tested at gameplay distance.
Where should I adjust sound volume?
Start with the AudioSource in the Inspector. This keeps the scene or prefab editable and lets the team tune the mix without changing the triggering script.
Can I use the same AudioSource for several effects?
Yes for a small local group of transient effects. Separate sources help when you need independent volume, routing or spatial behavior.
