For whatever reason, Network.connections.length, is always returning zero! Even when I (The host of a server) have successfully connected to my game!
Same luck with Network.connections.Length…
I need the for a function in my script - Players have all ready connected, and are made to wait to be spawned… Likewise, instead of being spawned on join, I have a script iterate through the array of connections, instantiate an object, and assign the object to the player that it was instantiated for.
Here is my code:
@RPC
function loadplayers()
{
cons = Network.connections;
Debug.Log("Hello?" + cons.Length);
for (i = 0; i < cons.Length; i++)
{
var pos : Vector3;
pos = transform.position;
var clone = Network.Instantiate(playerPrefab, pos, transform.rotation, 0);
var script1 : datan;
script1 = clone.GetComponent(datan).child.GetComponent(datan);
script1.spawn = transform;
script1.GetComponent(NetworkView).owner = cons[i];
Debug.Log(Network.connections.length);
con = Network.connections.length;
}
}
Oh, and though there is a “@RPC” up there, I am not calling the function with an RPC yet, I want to get the function working first.
I also have another snippet of code, in my Update function.
Debug.Log(Application.loadedLevel +“:::”+ Network.connections.length);
I’ve tried both length, and Length, with the same result.
Finally, I’ve tried loading data from Network.connections[0].ipAddress, causing the script to stop working at that point.
It’s as if I don’t exist to the server, when I’m perfectly connected! :?