- Home /
Check if a player has Network View
In the end this script will make the camera follow the player, but first I need to check if the player is from this client or somebody else's.
var aPlayer:Transform;
function Start()
{
var nView : NetworkView;
nView = aPlayer.GetComponent(NetworkView);
if(nView.isMine)
{
Debug.Log("WORKED");
}
}
I use a spawn script to initialize the player as a clone when the server is initialized or when you connect to come
Sadly this doesn't seem to work? I don't throw any errors but there's no Debug either.. can anybody explain to me how I can work this?
Thanks!
I guess that means the player doesn't own the networkView
. How are you instantiating the player? with Network.Instantiate
?
If so, who calls it, the player or the server? Whoever calls the Network.Instantiate
owns that object.
does all the objects gets instantiated from server itslef or is it from each player separately? if it is not from server networkview.is$$anonymous$$ine should help you
Network.Instantiate(aPlayer,transform.position,transform.rotation,0); is how the playing is being instantiated... then I want to do something like this:
Vector3 correctTarget = new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z); transform.LookAt(correctTarget);
to place the camera in a spot behind and above the player.
Who calls the Network.Instantiate
? It has to be the player (client) if you want them to control it.
There is another solution, albeit somewhat more complex, to obtain ownership of a networkView
. If a network peer calls Network.AllocateViewID
and then everyone applies that allocated viewID
(the peer who called it can send it to all via a RPC) to the networkView
of that object, then the player who called the allocation now owns the networkView
as well.
Basically players own viewID
(s). Network.Instantiate
just deals with the allocation and assignment of viewID
behind the scenes so you don't have to do it manually.