Help with sound (503804)

hey.. i am doing a little game and i am a 3d artist not a programmer :confused:
all i need is 2 sounds

  1. wen the door animation starts

  2. wen i walk

  3. i have a script that open the door with animation wen the player is close to it:

using UnityEngine;
using System.Collections;

public class Door : MonoBehaviour {
	public float check;
	private Animation anim;
	private Vector3 pos;
	
	void Start () {
	anim=animation;
		pos=transform.position;
	}
	void Update () {
	float dist=Vector3.Distance(pos,EpicCitadelControl.t.position);
		anim["Door_02"].normalizedTime = 1-dist*check;
		
			

	}
}
  1. i use the Epic Citadel Control for the movement and i what that wen ever i move the sound will get played
    the script:
    http://wiki.unity3d.com/index.php/Tap_to_Move_Drag_to_Look_iPhone

on both objects i put Audio Source with the sound i want them to play

tnx for anyone that can Help me :slight_smile:

Look at the AudioSource class.

like i sad i am not a programmer i don’t know that to do :confused:

Look at AudioSource

public AudioClip thisSound;/// make this variable public, so you can assign it in the editor.

void Start()
{
audio.clip = thisSound;
audio.Play();
}

:stuck_out_tongue:

If you want to assign a clip, it’ll be AudioClip, not AudioSource. An AudioSource is a component attached to a game object in order to play a sound (which you can simply call this.audio to call the AudioSource attached to the game object that the script is attached to).

In the OP case, he’d probably want to have a boolean to play the AudioSource for the door so he’ll only call play once. As you’ve already got your open door code, you’ll just need to set a boolean to be true then play the sound only when it is true. Set it false after that.

Yes, I already edited it.
That code is safe. It is late. And I have not touched audio for a while. Hopefully that helps.

ok… so where supposed to put the script ?
i need to tell him where to start playing the audio ?
in the “Epic Citadel Control” script where do i have a comend that says now i player is moving that i can put the “audio.Play();” ?
same with the door ?

Sorry for the ignorance

Please help me, I’m desperate

As you’ve already got the result for your distance check, you’ll probably want to start from there. So check if your distance is close enough for your door to be triggered to open. If it is close enough, play the sound. Please don’t just copy straight out.

if(dist < distanceToOpenDoor)
{
    if(!audio.isPlaying) // Keeps playing the audio if it is not playing
    {
        audio.Play();
    }
    // OR
    if(!hasAudioPlayed) // Plays audio once until you reset it
    {
        audio.Play();
        hasAudioPlayed = true;
    }
}

The above code shows 2 possible way to go about doing your audio, depending on your needs.

As for your player, you’ll need to check if your player is moving then check if the audio is playing. If the player is moving but the audio is not playing currently, you’ll want to play the audio.

I’d recommend you to read up some basic scripting tutorial. Saying you’re just an artist and not a programmer isn’t a good excuse to skip out on some basic scripting knowledge.

TNX !