Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

If Audio Clip is playing

Discussion in 'Scripting' started by herpderpy, Jan 24, 2011.

  1. herpderpy

    herpderpy

    Joined:
    Mar 9, 2010
    Posts:
    477
    Hi Everyone,

    Iv been stuck on a script for a few hours now, and can't seem to get it to work. So here's some of my script:

    Code (csharp):
    1. if(audio.isPlaying == true){
    2.     //some code
    3.     }
    4.     else
    5.     {
    6.     //some more code
    7.     }

    Obviously this script doesn't work, but I was wondering how I would get a script of this meaning to work?

    Thanks,

    Alex
     
  2. Freelax

    Freelax

    Joined:
    Oct 4, 2009
    Posts:
    24
    hi!

    Test this

    if(audio.isPlaying){
    //some code
    }
    else
    {
    //some more code
    }
     
  3. herpderpy

    herpderpy

    Joined:
    Mar 9, 2010
    Posts:
    477
    Nope, that's not working..
     
  4. Freelax

    Freelax

    Joined:
    Oct 4, 2009
    Posts:
    24
  5. herpderpy

    herpderpy

    Joined:
    Mar 9, 2010
    Posts:
    477
    Okay so it's registering that, now I need to get a else command. Although when I use :

    Code (csharp):
    1. if(!audio.isPlaying){
    2.    
    3.     }
    4.     else
    5.     {
    6.     //Where I want my code
    7.     }

    It doesn't seem to do the code...
     
    Last edited: Jan 24, 2011
  6. HDDEAD

    HDDEAD

    Joined:
    Jan 24, 2011
    Posts:
    18
    try this:

    var audioFile : AudioClip;

    if(audioFile.isPlaying){

    //some code here

    }else{

    //some other code

    }

    to use else, first you need an if statement. Hope i was hopeful