I am trying to link the audio source from a VoiceChat example to my playerPrefab.
But I can’t figure out how to do it?
When a network player joins, a “playerPrefab” is created in OnServerAddPlayer for all clients,
At the same time a voicechat “proxyPrefab” is created in OnStartClient for all clients.
How do I know which proxyPrefab was created for which playerPrefab?
My LobbyManager snippit:
public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId) {
//Add the playerPrefab to the lobby scene and give it authority
GameObject iObject = NetworkServer.FindLocalObject ( newLobbyGameObject.GetComponent<NetworkIdentity> ().netId );
var playerPrefab = Instantiate(gamePlayerPrefab, Vector3.zero, Quaternion.identity);
NetworkServer.SpawnWithClientAuthority (playerPrefab, iObject);
}
public override void OnStartClient(NetworkClient client) {
VoiceChatNetworkProxy.OnManagerStartClient(client);
}
#region NetworkManager Hooks
public static void OnManagerStartClient(NetworkClient client, GameObject customPrefab = null)
{
client.RegisterHandler(VoiceChatMsgType.Packet, OnClientPacketReceived);
client.RegisterHandler(VoiceChatMsgType.SpawnProxy, OnProxySpawned);
proxyPrefab = Resources.Load<GameObject>(ProxyPrefabPath);
ClientScene.RegisterPrefab(proxyPrefab);
}
[UPDATE]
This is turning out to be the hardest thing I have ever had to do with Unity! A true nightmare and I mean it sucks!!
I fear I will get no help and will be fighting this for a very long time.
If I understood UNET better I might be able to figure it out, and it seems so simple, but Unity makes these things impossible and it’s super frustrating!!!.
I have now just wasted my entire night/morning on this and am more confused then when I started.
Is UNET incapable or is it me???