Audio Source and Clip Problems in unity3d 5.0.0

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 :rage:
Even in the unity3d Scripting Reference the Example code do not work and unity3d give error :face_with_spiral_eyes:

#pragma strict
@RequireComponent(AudioSource)
public var otherClip;
function Start() {
    var audio = GetComponent.<AudioSource>();
    audio.Play();
    new WaitForSeconds(audio.clip.length)audio.clip = otherClip;
    audio.Play();
}

Simply I want to change my Audio clip in audio source!
thanks in advance

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:

    #pragma strict
    @RequireComponent(AudioSource)
    public var otherClip;
    function Start() {
        var audio = GetComponent.<AudioSource>();
        audio.Play();
        new WaitForSeconds(audio.clip.length);
        audio.clip = otherClip;
        audio.Play();
    }
1 Like

Yes that’s it , How I can tell unity3d to solve this code problem on Scripting reference ?

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!

1 Like

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!

1 Like