- Home /
How can i make so one sound changes location?
I want a scary whisper sound to go around my character. Like starts at back, continues to the left, then front, then to the right. How can i do this? My character must also be able to move.
u might need to implement some kind of surround sound check this link
http://answers.unity3d.com/questions/195719/surround-quad-unity-with-four-speakers.html
Answer by fafase · Aug 24, 2012 at 05:42 PM
Create an empty game object and attach the audio source to it. You can move the game object like any other.
Here is a simple script that gets the player in a zone and the object will rotate around it for 10 seconds: -Create a trigger box and attach this:
var onlyOne:boolean=true;
function OnTriggerEnter(other:Collider){
if(other.gameObject.tag=="Player")Create(other.gameObject.transform);}
function Create(pos:Transform){
if(onlyOne){
var obj = Instantiate(prefab,pos.position,Quaternion.identity)
obj.transform.parent = pos;
onlyOne =false;
}
}
And on the prefab you have this script:
var timer:float=10;
function Update(){
timer-=Time.deltaTime;
if(timer>0)
transform.position=Vector3(Mathf.Cos(2*Time.timeSinceLevelLoad),0,
Mathf.Sin(2*Time.timeSinceLevelLoad));
else Destroy(gameObject);
}
Your prefab is a simple game object with an audio source and a audio clip with play on awake. When the player enters the zone the object will start spinning around him and follow him for 10 seconds.onlyOne makes sure the object does not get created many times.
I tried, but i have no fucking idea of what you mean. This is too difficult.
Ok, let's start slowly. You place an empty game object in your scene then you add a box collider to it. This collider you set it to IsTrigger, that means you won't bounce on it but just get through it. The whole entity is not visible is an invisible sas. Now you have the first part attached as a script.
Previously, you prepare another empty game object, you add an audio source, the file you want to play (like"Bouhou you scared?") and in the AudioSource component you tick PlayOnAwake, that starts the audio file automatically. Then you attach the second script to it. Create a prefab and drag and drop that object,now remove it from the scene. In the first script back you add:
var prefab:GameObject;
then you drag and drop the prefab you just made.
When your player will enter the sas, an invisble object because empty will start spinning around your player following him. As there is an audio source playing, the sound is moving around you, the player. Get it?
if you multiply the Cos and Sin with different values you get a more interesting effect of boomerang ins$$anonymous$$d of plane circle. your object disappears after 10s. (now you're scared).
I was thinking of animation and animatin event but I will probably get you lost.
Other way, to finish with this, you can have array of positions ins$$anonymous$$d of trig functions. your object is spinning around the player but jumping from one position to another in space.
Hope that clarify a little.
I get the principle here, but theoretically is there any way to do this without having to manually create invisible game objects to control the transform of the audio sources? I want to do something along these lines with potentially every audio source in a scene, so ideally I want to be able to programmatically create empty game objects or similar to move audio sources as and when needed.. can this be done?