{"id":15833381,"url":"https://github.com/davealdon/unity3d-audio-tricks","last_synced_at":"2026-03-18T17:01:57.184Z","repository":{"id":221760303,"uuid":"754454033","full_name":"DaveAldon/Unity3D-Audio-Tricks","owner":"DaveAldon","description":"Simple audio tricks to use that polish your user's experience","archived":false,"fork":false,"pushed_at":"2024-02-09T22:16:23.000Z","size":2357,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-26T06:06:35.866Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"ShaderLab","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DaveAldon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-08T04:42:50.000Z","updated_at":"2024-02-09T21:53:22.000Z","dependencies_parsed_at":"2024-02-09T22:44:00.599Z","dependency_job_id":null,"html_url":"https://github.com/DaveAldon/Unity3D-Audio-Tricks","commit_stats":null,"previous_names":["davealdon/unity3d-audio-tricks"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaveAldon%2FUnity3D-Audio-Tricks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaveAldon%2FUnity3D-Audio-Tricks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaveAldon%2FUnity3D-Audio-Tricks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaveAldon%2FUnity3D-Audio-Tricks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DaveAldon","download_url":"https://codeload.github.com/DaveAldon/Unity3D-Audio-Tricks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246635987,"owners_count":20809333,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-05T13:02:14.848Z","updated_at":"2026-01-08T08:39:21.920Z","avatar_url":"https://github.com/DaveAldon.png","language":"ShaderLab","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unity3D-Audio-Tricks\n\nI've got two tricks for you today that help add some polish to any app or game with repetitive audio, or that needs any volume controls.\n\n1. If your game has a lot of repetitive audio, you can add a small amount of randomness to the pitch to make it sound more natural. This is **super** useful for footsteps, weapon sounds, or anything that has to play over and over.\n\n2. If your game has a volume control (it better have one!), keep in mind how volume works. It's not linear, it's logarithmic. A lot of libraries out there, and even basic implementations in Unity, will handle this, but can easily slip through the cracks.\n\n![Cube shooting a sphere](Resources/demo.gif)\n\nI've included a [Mac compatible build](https://github.com/DaveAldon/Unity3D-Audio-Tricks/releases/tag/mac-build) with a simple scene that demonstrates these two tricks and how they can impact your game. You can try it out right now without needing to install anything.\n\n### How to use the pitch trick\n\nEssentially, whenever you call your audio clip to play, include a pitch value that is slightly randomized. Here's an example in C#:\n\n```csharp\n  [SerializeField]\n  private AudioClip shootSound;\n  private AudioSource _audioSource;\n\n  IEnumerator ShootProjectile()\n  {\n    while (true)\n    {\n      GameObject projectile = Instantiate(projectilePrefab, transform.position, Quaternion.identity);\n      projectile.GetComponent\u003cRigidbody\u003e().AddForce(transform.forward * projectileSpeed);\n\n      if (shootSound != null)\n      {\n        // Random pitch value\n        _audioSource.pitch = Random.Range(0.5f, 1.2f) : 1.0f;\n        _audioSource.PlayOneShot(shootSound);\n      }\n      yield return new WaitForSeconds(shootInterval);\n    }\n  }\n```\n\nAbove is with the built-in audio management in Unity. But there's other audio managers out there. One of my favorites is the [More Mountains Feels](https://feel.moremountains.com/) plugin. Pitch is just as easy to modify with this library. Here's example of setting up an options object that modifies a clip:\n\n```csharp\n  MMSoundManagerPlayOptions options;\n  options = MMSoundManagerPlayOptions.Default;\n  options.Pitch = UnityEngine.Random.Range(0.5f, 1.2f);\n  options.SpatialBlend = 1;\n  options.AttachToTransform = transform;\n  options.MmSoundManagerTrack = MMSoundManager.MMSoundManagerTracks.Other;\n```\n\nMake sure to run the Unity project in this repo and toggle the checkbox in the UI to hear the difference. Pitch makes a **huge** difference when you throw in repetition.\n\n### How to use the volume trick\n\nThe volume trick depends on the audio manager you're using, and the slider values. I like to have a slider that goes from 0 to 100 with whole numbers, so I use a formula like this to convert it to whatever scale I need:\n\n```csharp\n  public void SetLinearVolume(float sliderValue)\n  {\n    float volume = sliderValue / 100f;\n    AudioListener.volume = volume;\n  }\n\n  public void SetLogarithmicVolume(float sliderValue)\n  {\n    float db = -80 + (sliderValue * 0.8f);\n    float volume = Mathf.Pow(10, db / 20);\n    AudioListener.volume = volume;\n  }\n```\n\nYou could just as easily use a 0-1 scale, which is the default for Unity sliders. The important part is making sure that the **_entire volume slider is usable_**, and not just the first or last 10% of it. This is especially important for mobile games, where the user might not have super granular control over the slider.\n\n### Conclusion\n\nI hope these tricks were helpful for you! Some boilerplate stuff about the repo below:\n\n1. The project was made with Unity3D `2023.2.7f1`\n2. The UI uses TextMeshPro\n3. The audio clip is some random free laser sound I found\n4. Everything else is using built-in stuff\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavealdon%2Funity3d-audio-tricks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavealdon%2Funity3d-audio-tricks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavealdon%2Funity3d-audio-tricks/lists"}