- Home /
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
Answer by Nicolaj Schweitz · Apr 08, 2010 at 10:01 AM
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.
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.
Answer by straydogstrut · Apr 07, 2010 at 10:35 PM
Take a look at this question which explains the different methods of playing audio.
Thanx I read that, but sorry that didn't solve my entire issue. It helped though.