multiplayer camera problems

I’m trying to make a networked game. But I’ve been stuck for days on this problem. I can’t get the camera’s right for each player. I’ve tried so many things to get this working. I’m stumped.

This is my spawnscript for creating a new player when someone connects:

#pragma strict

public var playerPrefab : Transform;


function OnServerInitialized(){
	Spawnplayer();
}

function OnConnectedToServer(){
	Spawnplayer();
}

function Spawnplayer(){
	
	var myNewTrans : Transform = Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);

	var cameraX = GameObject.Find("Main_Camera");    

	var follow = cameraX.GetComponent("SmoothFollow");    

	follow.SendMessage("SetTarget", myNewTrans);
	//follow.target = myNewTrans;

}




function OnPlayerDisconnected(player: NetworkPlayer) {
	Debug.Log("Clean up after player " + player);
	Network.RemoveRPCs(player);
	Network.DestroyPlayerObjects(player);
}

function OnDisconnectedFromServer(info : NetworkDisconnection) {
	Debug.Log("Clean up a bit after server quit");
	Network.RemoveRPCs(Network.player);
	Network.DestroyPlayerObjects(Network.player);
	Application.LoadLevel(Application.loadedLevel);
}

And my MainCamera’s script looks like this:

// The target we are following
var target : Transform;
// The distance in the x-z plane to the target
var distance = 10.0;
// the height we want the camera to be above the target
var height = 5.0;
// How much we 
var heightDamping = 2.0;
var rotationDamping = 3.0;

// Place the script in the Camera-Control group in the component menu
@script AddComponentMenu("Camera-Control/Smooth Follow")


function LateUpdate () {
	// Early out if we don't have a target
	if (!target)
		return;
	
	// Calculate the current rotation angles
	wantedRotationAngle = target.eulerAngles.y;
	wantedHeight = target.position.y + height;
		
	currentRotationAngle = transform.eulerAngles.y;
	currentHeight = transform.position.y;
	
	// Damp the rotation around the y-axis
	currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);

	// Damp the height
	currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);

	// Convert the angle into a rotation
	currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
	
	// Set the position of the camera on the x-z plane to:
	// distance meters behind the target
	transform.position = target.position;
	transform.position -= currentRotation * Vector3.forward * distance;

	// Set the height of the camera
	transform.position.y = currentHeight;
	
	// Always look at the target
	transform.LookAt (target);
}

function SetTarget (t : Transform)
{
	Debug.Log("EEE");
	target = t;
}

I’ve tried this every which way, it just doesn’t work. Here’s what I’ve figured out so far.

  1. follow.SendMessage(“SetTarget”, myNewTrans); or follow.target = myNewTrans; neither of these will work on a the webplayer or standalone. They only work inside the editor. Which leaves me with no way of changing the target on my camera’s script in a standalone.
  2. Most examples I’ve seen only use one camera, but they set it to have multiply targets, one for each character that connects.

I’ve developed in C++, C#, assembly language, Java and numerous other scripting languages. I’ve never had this much trouble with anything before. Is scripting for Unity always this insanely difficult? Does anyone know how to fix my problem?

Everythink is ok when you are playing in the editor but it is not working when you build ?

Since you don’t have the console, you will have to use OnGUI.

var textDebug : String;

function OnGUI () {
	GUI.Label (Rect (50, 50, 400, 50), textDebug);
}

Try getting the part where something goes wrong ?