Tried posting this before, got no answers, trying again.
Got a project where a dedicated authorative server, without a local player on it, runs the show. Clients connect and control only their own object, and naturally should also only look through their object’s camera. This is the problem.
Here’s the code (JavaScript) I’m using, trying to assign the correct camera to the right player:
@RPC
function SetPlayer(player : NetworkPlayer, viewID : NetworkViewID) {
owner = player; // Set the local player as owner
if (Network.isClient) {
var allCams = FindObjectsOfType(Camera); // Set var and find all cameras
for (var cam : Camera in allCams) { // For-var loop through list of all cameras
cam.enabled = false; // Disable them
}
if (owner == Network.player) { // If this is the owner
var myCam0 = this.gameObject; // Set var to the parent
var myCam = myCam0.camera; // Set var to the component of parent
myCam.enabled = true; // Enable this camera
enabled = true; // Enable the script, ownership granted
}
}
}
This triggers only when the server sets a new owner to a newly instatiated object, kept the camera disabling and re-enabling out of Update() to reduce load.
The problem appears when I test this from editor, and then try to connect a new player via standalone build. The editor client’s camera gets set to the new object’s camera (which is supposed to belong to the new player), and the new player’s view is locked at dark blue background, i.e. he’s not seeing anything (might not be loading the level correctly, but still there’s a camera issue).
I am following Leepo’s tutorial, and I am also following the code of Rodrigo G., who was doing the same thing I’m trying here; but his code isn’t working out for me, for some reason. (The link to his thread: http://forum.unity3d.com/viewtopic.php?t=42873.)
What am I doing wrong? Hoping for replies this time.