- Home /
AudioMixer Snapshot Problem
Hello!
I'm doing a multiplayer game and I wonder how I can make the following effect:
https://www.youtube.com/watch?v=FNqFMCa6KQM
I was thinking of doing different snapshots, audio Mixer, and with a script to do that when the audiolistener is located at a certain distance to change the snapshot on the other, I tried that but I can't get it.
I hope soon to be fixed thank you sorry if my English is bad.
I created a script that makes changing from one snapshot to another when a GameObject is a certain distance, the problem is that there are many players and the script only takes into account only one of them (because is a $$anonymous$$ultiplayer game) and others not, so for those players do not change the snapshots, if anyone knows how to fix it please respond.
using UnityEngine;
using System.Collections;
using UnityEngine.Audio;
public class Sound : $$anonymous$$onoBehaviour {
public Transform target;
private Transform myTransform;
public Audio$$anonymous$$ixerSnapshot Snapshot1;
public Audio$$anonymous$$ixerSnapshot Snapshot2;
public Audio$$anonymous$$ixerSnapshot Snapshot3;
public Audio$$anonymous$$ixerSnapshot Snapshot4;
public Audio$$anonymous$$ixerSnapshot Snapshot5;
void Awake()
{
myTransform = transform;
}
// Use this for initialization
void Start ()
{
GameObject go = GameObject.FindWithTag("Player");
target = go.transform;
}
// Update is called once per frame
void Update ()
{
float dist = Vector3.Distance(target.position, transform.position);
if (dist >= 0)
{
Snapshot1.TransitionTo(0.01f);
}
if (dist >= 10)
{
Snapshot2.TransitionTo(0.01f);
}
if (dist >= 15)
{
Snapshot3.TransitionTo(0.01f);
}
if (dist >= 20)
{
Snapshot4.TransitionTo(0.01f);
}
if (dist >= 30)
{
Snapshot5.TransitionTo(0.01f);
}
}
}
Answer by boombostak · Apr 07, 2016 at 10:40 AM
Hi @Xpadrian2010 ,
Try AudioMixer.TransitionToSnapshots and use the distance to determine weights. Here is part of the code to do a similar thing using points in space (nodes) that are associated with a snapshot.
for (int i = 0; i < node_array.Length; i++) {
closenesses[i] = 1/
Vector3.Distance(node_array[i].transform.position,
target.transform.position);
public void BlendSnapshots()
{
mixer.TransitionToSnapshots (snapshot_array, distances_to_nodes_array, 0.005f);
}
This weights the transition based on irregularly spaced nodes. For your problem you would either want to have only 2 snapshots (very close and very far) and blend between them, or figure out a way to set your weights based on specific intervals of distance from the source (if it's in 5 meter intervals, maybe testing if distance%5==0). Hope this helps.
Your answer
Follow this Question
Related Questions
FPS, Trying to add sound to footsteps, Not working! 2 Answers
Check if RaycastAll hits[i].point == null 0 Answers
Remove first element of array 1 Answer
How to make a camera work in this circumstance. 1 Answer
Database connection FPS game? 0 Answers