Assigning the camera's target on a newly instantiated player

Hello, I’m new to Unity. I’m using very basic networking. The line that instantiates my new players looks like:

var myNewTrans : Transform = Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
(from the networking tutorial, part 2b spawnscript)

this creates a player object, which has a camera as a child. I think i need to set my Camera’s target field, but i have no idea how to say that in javascript.

Right now i just have the camera’s target set to the player prefab. But i think it gets confused when multiple players are instantiated, cuz the camera on player 1 flips to player 2 when he gets instantiated, and likewise, player 2’s camera flips over to targeting player 1.

Any help would be appreciated.

GetComponentsInChildren(yourscriptname).myvariable = myCamera

I use the smoothfollow script to follow my player and set it’s target this way.

i don’t understand.

first of all, i dont understand how a player can be instantiated as a transform…that doesn’t make sense to me.

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

because of this and because i’m new to javascript i don’t know how to point at components of this newly instantiated player.

your instantiating your player as a transform to be able to move it afterwards.
In the docs there is a big chapter about instantiating.

still can’t figure out why this isn’t working

var myNewTrans : Transform = Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
myNewTrans.Find(“camera”).GetComponent(MyCamera).target = myNewTrans;

it says:

‘target’ is not a member of ‘UnityEngine.Component’

I’ve double checked the spellings, tried caps and not caps everywhere. Can anyone help me out here?

ps. thx for the advice so far appels

you must be making a mistake somewhere.
This is how i do it :
cam = GameObject.Find(“Main Camera”);
sf = cam.GetComponent(SmoothFollow);
sf.target = this.transform;

that works just fine.