Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Beginner Space Shooter: Audio

Discussion in 'Getting Started' started by Napivo, Feb 10, 2015.

  1. Napivo


    Feb 9, 2015
    Well it seems to work fine

    Add sound to player
    Call it from code

    But why would I want to do that if I can
    Add sound to bolt
    Play it when spawned

    This would give me the added advantage to have different kind of bolts each with their own sound and no coding, or am I wrong?
  2. roger0


    Feb 3, 2012
    There's nothing wrong with adding a sound effect to the bolt and playing it when spawned. For the character, it depends on what you want to achieve. If you want to add variations to a triggered sound effect like swinging a sword, you can do that by making an audioclip array and calling a random sound effect from the array when the action is done, You could also do this with your bolt if you want to have a variety of sound effects to play when it is spawned, like this.

    Code (CSharp):
    2.     public AudioClip [] audioClips;
    4.     void Start () {
    6.         audio.clip = audioClips[Random.Range (0,audioClips.Length)];
    7.         audio.Play ();
    8.     }