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

(stop sound) What's the problem in this code?

Discussion in 'Scripting' started by abramelingames, Jul 24, 2015.

  1. abramelingames

    abramelingames

    Joined:
    Jul 15, 2015
    Posts:
    44
    Code (JavaScript):
    1. var soundon : AudioClip;
    2. var soundoff : AudioClip;
    3.  
    4. function OnTriggerEnter () {
    5.  
    6. GetComponent.<AudioSource>().PlayOneShot(soundon);
    7. GetComponent.<AudioSource>().audio.Stop(soundoff);
    8. this.GetComponent.<Collider>().enabled = false;
    9. }
    the second sound (soundoff) not appears, the code works except this lines

    -var soundoff : AudioClip;
    -GetComponent.<AudioSource>().audio.Stop(soundoff);

    where is the fail?
     
  2. chronochris

    chronochris

    Joined:
    Jun 7, 2015
    Posts:
    61
    .Audio.Stop?
     
  3. abramelingames

    abramelingames

    Joined:
    Jul 15, 2015
    Posts:
    44
    -GetComponent.<AudioSource>()audio.Stop(soundoff);

    thats okay now?
     
  4. chronochris

    chronochris

    Joined:
    Jun 7, 2015
    Posts:
    61
    I looked up the scripting API. Their example declares var audio: AudiSource = GetComponent.<AudioSource>();
    From there you can just run audio.Stop();
     
  5. abramelingames

    abramelingames

    Joined:
    Jul 15, 2015
    Posts:
    44
    how can i add the second soundoff correctly? when the player enter the trigger, play a music and stop other...
     

    Attached Files:

  6. abramelingames

    abramelingames

    Joined:
    Jul 15, 2015
    Posts:
    44
    seems solved


    GetComponent.<AudioSource>().soundoff.Stop();
     
  7. chronochris

    chronochris

    Joined:
    Jun 7, 2015
    Posts:
    61
    I think some good tutorials for javascript should help you. This is exactly what I said in my post to you. :p