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

How to loop a sound clip.

Discussion in 'Scripting' started by Noah492, Oct 14, 2015.

  1. Noah492

    Noah492

    Joined:
    Jul 2, 2014
    Posts:
    44
    So I want to have my sound play on a loop when in a trigger. This works for only the duration of the sound. I don't know if the solution is to use source.Play (); because it doesn't work/I don't know how to use it.
    How can I make my clip loop?

    void Start ()
    {
    source = GetComponent<AudioSource> ();
    }

    void OnTriggerEnter ()
    {
    source.PlayOneShot (clip);
    }
     
  2. vintar

    vintar

    Joined:
    Sep 18, 2014
    Posts:
    90
    So in your audioSource there is a toggle for "Loop", just click it ;)
    But be sure to drag your audioclip into the source in the inspector.
    source.Play() to play and source.Stop() to stop it.
     
  3. Ian094

    Ian094

    Joined:
    Jun 20, 2013
    Posts:
    1,548
    Set loop to true :
    Code (CSharp):
    1. source.loop = true;
    2. source.Play();
     
    Who-am-I likes this.