Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Replacing the audio randomly from an object.

Discussion in 'Audio & Video' started by maxrio, Sep 7, 2015.

  1. maxrio

    maxrio

    Joined:
    Jan 8, 2015
    Posts:
    25
    Greetings.I must enter 3 sound on an object, but each time it is activated the audio has to be random. What's the procedure? I thank you.
     
  2. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    Make an array of AudioClips and use Random.Range to pick one at random and assign it to the AudioSource, then play it.
     
  3. maxrio

    maxrio

    Joined:
    Jan 8, 2015
    Posts:
    25
    Thanks for the help but could put an example because I am new to Javascript and I'm with some difficulty to create this script. Anyway thank you.