x


Phone Ringing audio scripting help

Hi, I'm trying to make a phone ring and when you get near it the ringing stops and a voice audio takes its place. I just can't seem to do it though. I wrote the script but it says "Play" isnt part of Unity Engine Audio Clip. Here is my script:

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

    }   
}
more ▼

asked Apr 08 '10 at 02:18 AM

DTJ Productions gravatar image

DTJ Productions
57 19 20 25

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

1 answer: sort voted first

Play() is for an audio source, not an audio clip. You have to assign the audio clip to the audio source if you haven't already, then do audio.Play(), assuming that the audio source you want to play is attached to the same object that the script is. Or if the audio source is on the other object:

function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.collider.gameObject.tag == "hippo")
    {
        hit.collider.audio.clip = myAudioFile;
        hit.collider.audio.Play();
    }   
}
more ▼

answered Apr 08 '10 at 02:31 AM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

My script is attached to my Player since its collision, i need my player to like touch the phone and then the audio plays. So can you throw that by me again? My audio clip is attached to the source.

Apr 08 '10 at 02:37 AM DTJ Productions

@DTJ Productions: see the edit I made to my answer.

Apr 08 '10 at 04:51 AM Eric5h5

Thanx that worked, I only have one problem- turning the ringing off when I touch the "hippo" game object. Please help

Apr 10 '10 at 01:47 AM DTJ Productions

@DTJ Productions: If the ringing is being produced by the "hippo" object's audio source, then replacing it with "myAudioFile" like the script already does should stop the ringing.

Apr 10 '10 at 03:14 AM Eric5h5

That did not help, I have a noise playing "On Awake" and need it to stop the time I touch the object or the time the other audio turns on.

Apr 10 '10 at 04:47 AM DTJ Productions
(comments are locked)
10|3000 characters needed characters left

You need to access the Audio Source Component of the phone GameObject, then tell that to play. I think this will work:

private var phone : GameObject;

function Awake() {
phone = GameObject.Find("Phone");
}

function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.collider.gameObject.tag == "hippo")
    {
        phone.audio.Play();

    }   
}

Or you can make "phone" a public variable and set it in the Editor.

more ▼

answered Apr 08 '10 at 03:59 AM

Design3.com gravatar image

Design3.com
640 1 1 10

Hey I was wondering for the OnControllerColliderHit function and it says phone.audio.Play(); Do I name my audio sound that I want to play "phone"?

Apr 09 '10 at 01:23 AM DTJ Productions

Oh and also (sorry for these idiotic questions) I was wondering what to tag the object I want to touch and play the sound, and what to name it. thanks

Apr 09 '10 at 01:25 AM DTJ Productions

See Eric's answer. I think it'll work better for you in this case.

Apr 10 '10 at 12:03 AM Design3.com
(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:

x3465
x1031
x28
x1

asked: Apr 08 '10 at 02:18 AM

Seen: 1360 times

Last Updated: Apr 08 '10 at 02:29 AM