Camera issues [Solved]

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.

Well, I eventually managed to solve this partially.

I disabled the camera on the prefab by default, and skipped the disable-camera loop code. Then, through code, simply activated the camera for the object owner when owner was set.

@RPC
function SetPlayer(player : NetworkPlayer, viewID : NetworkViewID) {
	owner = player; // Set the local player as owner
	if (Network.isClient  owner == Network.player) {
		var myCam0 : GameObject = this.gameObject; // Set var to the parent
		var myCam : Camera = myCam0.camera; // Set var to the component of parent
		myCam.enabled = true; // Enable this camera
		enabled = true; // Enable the script, ownership granted
	}
}

But there’s still a remaining problem: the client connecting from the standalone still can’t see anything. The dark-blue background from the main menu scene stays there with nothing on-screen, after pressing the “Enter World” button. All this works perfectly in the Unity editor.

Does anyone know why it behaves like this?

Update: When adding a MainCamera to the scene and tagging it as such, the standalone client can then view through it. But still it should set its view to the object, this still doesn’t work.

Update 2: When placing the MainCamera at the spawnpoint of the objects, the standalone client sees nothing at all (and can not control anything), but the server registers the connection and spawns an object, and the in-editor client sees the new object. The standalone client’s object just sits there dead.

What’s going on with this behaviour? Anyone have a clue?

Solved, not quite sure how - I was tinkering around with putting all client-side scripts in their own collective prefab. Not sure if this was the magic trick that made it work.