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

Music Ambients With Tags and loop not works

Discussion in 'Audio & Video' started by DDAUDIOSOLUTIONS, Apr 10, 2016.

  1. DDAUDIOSOLUTIONS

    DDAUDIOSOLUTIONS

    Joined:
    Sep 5, 2015
    Posts:
    21
    Hi, i would like to use differents musics, and ambients, in my game, but to make it easy i want to use tags.

    I make tags and add this to the differents surfaces, or whatever for the player goes, and active the collider mesh, and the different musics and ambients sounds....BUT......How can i say to the script, that play the sound in loop while the player is in one of these places?

    My Script is:

    var Clip1 : AudioClip;
    var Clip2 : AudioClip;
    var Clip3 : AudioClip;
    var Clip4 : AudioClip;
    var Clip5 : AudioClip;

    function OnTriggerEnter(hit:Collider){
    if(hit.tag == "MainTheme"){
    GetComponent.<AudioSource>().Stop ();
    GetComponent.<AudioSource>().PlayOneShot(Clip1);

    }

    if(hit.tag == "Central"){
    GetComponent.<AudioSource>().Stop ();
    GetComponent.<AudioSource>().PlayOneShot(Clip2);
    }

    if(hit.tag == "Mistery"){
    GetComponent.<AudioSource>().Stop ();
    GetComponent.<AudioSource>().PlayOneShot(Clip3);
    }

    if(hit.tag == "ElectroRain"){
    GetComponent.<AudioSource>().Stop ();
    GetComponent.<AudioSource>().PlayOneShot(Clip4);
    }

    if(hit.tag == "Combat"){
    GetComponent.<AudioSource>().Stop ();;
    GetComponent.<AudioSource>().PlayOneShot(Clip5);
    }


    }


    I have tryed to add this between stop and start, but not works:
    GetComponent.<AudioSource>().loop = true;

    what can i do?

    thanks
     
  2. DDAUDIOSOLUTIONS

    DDAUDIOSOLUTIONS

    Joined:
    Sep 5, 2015
    Posts:
    21
    OK OK OK

    Is Fix It!!!!

    using this script that i found in other post

    part of my script now is:

    var Clip1 : AudioClip;
    var Clip2 : AudioClip;
    var Clip3 : AudioClip;
    var Clip4 : AudioClip;
    var Clip5 : AudioClip;

    function OnTriggerEnter(hit:Collider){
    if(hit.tag == "MainTheme"){
    GetComponent.<AudioSource>().Stop ();
    GetComponent.<AudioSource>().clip = Clip1;
    GetComponent.<AudioSource>().Play();
    GetComponent.<AudioSource>().loop = true;
    }
    ......


    Sometimes when i think talking i find the solutions!!!!