- Home /
Question by
SpeedTutor · Apr 22, 2013 at 04:24 PM ·
triggerobjectsounddistance
Trigger sound on another gameobject
Hello,
I know how to trigger a sound on an collision (On that empty gameobject).
using UnityEngine;
using System.Collections;
public class SoundTrigger : MonoBehaviour
{
public AudioClip Laughing;
void OnTriggerEnter(Collider other)
{
if(other.tag=="Weapon")
audio.PlayOneShot(Laughing);
}
}
But I want to know how to enter a certain collider but have the sound play elsewhere on another gameobject (in the distance), my notion is to guide the player. Sound being the item to guide them.
Thanks!
Comment
Best Answer
Answer by AlucardJay · Apr 22, 2013 at 04:46 PM
Use AudioSource.PlayClipAtPoint : http://docs.unity3d.com/Documentation/ScriptReference/AudioSource.PlayClipAtPoint.html
Plays the clip at position. Automatically cleans up the audio source after it has finished playing. (Just like PlayOneShot)