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.

Audio Source and Clip Problems in unity3d 5.0.0

Discussion in 'Scripting' started by alone1992, Apr 26, 2015.

  1. alone1992

    alone1992

    Joined:
    Oct 23, 2012
    Posts:
    156
    Hello Every one
    I have a Game Object that have an Audio Source , now I want to Control or change the audio clip by scripting but there is huge problem and that is unity3d 5 problem with new audio Scripting style :mad:
    Even in the unity3d Scripting Reference the Example code do not work and unity3d give error :confused:
    http://docs.unity3d.com/ScriptReference/AudioSource-clip.html
    Code (JavaScript):
    1. #pragma strict
    2. @RequireComponent(AudioSource)
    3. public var otherClip;
    4. function Start() {
    5.     var audio = GetComponent.<AudioSource>();
    6.     audio.Play();
    7.     new WaitForSeconds(audio.clip.length)audio.clip = otherClip;
    8.     audio.Play();
    9. }
    Simply I want to change my Audio clip in audio source!
    thanks in advance
     
  2. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    450
    Not sure if it'll solve your problem, but your code looks a bit off-kilter around line 7... It looks like it should be 2 lines instead... Try this and let me know if it helps:

    Code (JavaScript):
    1.     #pragma strict
    2.     @RequireComponent(AudioSource)
    3.     public var otherClip;
    4.     function Start() {
    5.         var audio = GetComponent.<AudioSource>();
    6.         audio.Play();
    7.         new WaitForSeconds(audio.clip.length);
    8.         audio.clip = otherClip;
    9.         audio.Play();
    10.     }
    11.  
     
    alone1992 likes this.
  3. alone1992

    alone1992

    Joined:
    Oct 23, 2012
    Posts:
    156
    Yes that's it , How I can tell unity3d to solve this code problem on Scripting reference ?
     
  4. hamsterbytedev

    hamsterbytedev

    Joined:
    Dec 9, 2014
    Posts:
    353
    Contact support, file a bug report, and perhaps look at some of the tutorial literature. That is beginner mistake and it must have been underlined red in MonoDevelop. Good luck. Keep at it!
     
    alone1992 likes this.
  5. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    450
    Nice catch alone1992! It's not every day you see a mistake in the docs (though I'm sure it happens from time to time). I suppose Hamsterbyte.LLC's suggestion is best; contact support and/or file a bug report. Let them know which page of the documentation needs to be corrected, and be sure to let them know that it's the Javascript example that needs to be fixed (the C# example looks solid). Have fun!
     
    alone1992 likes this.