x


Can't play audio file

Hey, I'm trying to make a telephone ring, and when you get close to it, the ringing stops and another audio plays. I can't seem to get the audio to stop and the other audio to play like when I touch it or something else. I tried this:

function OnControllerColliderHit(hit : ControllerColliderHit)
{ 
if(hit.collider.gameObject.tag == "audiostart")
    {
        myAudioFile.Play();

    }

and it says

Assets/Scripts/collisions 1.js(21,29): BCE0019: 'Play' is not a member of 'UnityEngine.AudioClip'.

Please help

more ▼

asked Apr 07 '10 at 10:23 PM

DTJ Productions gravatar image

DTJ Productions
57 19 20 25

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Unity tells you that you are trying to play an audio clip. You can't do it like that.

What you need to do is to attach the clip to an audio source, then tell the audio source to play.

Im short, a clip is a file that has to be put on a audio source component on a gameobject. Then you can handle the audio.

http://unity3d.com/support/documentation/Manual/Sound.html explains the terms in more depth.

more ▼

answered Apr 08 '10 at 10:01 AM

Nicolaj Schweitz gravatar image

Nicolaj Schweitz ♦♦
1.6k 19 26 57

I did attach it to an audio source. Here is what Ive got; two audio sources on one object; The first audio source is a play when awake, to play ringing. The second audio source is not on awake, I want that to play when I touch the gameObject.

Apr 09 '10 at 01:28 AM DTJ Productions
(comments are locked)
10|3000 characters needed characters left

Take a look at this question which explains the different methods of playing audio.

more ▼

answered Apr 07 '10 at 10:35 PM

straydogstrut gravatar image

straydogstrut
1.2k 29 38 60

Thanx I read that, but sorry that didn't solve my entire issue. It helped though.

Apr 08 '10 at 02:13 AM DTJ Productions
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1944
x1025
x224
x198
x111

asked: Apr 07 '10 at 10:23 PM

Seen: 4076 times

Last Updated: Apr 07 '10 at 10:50 PM