- Home /
[Multiplayer]How to individualize the Player
I'm creating a MultiPlayer system, he is already ready, but now I have the problem of locating the Players. Note: I am Brazilian, excuse my bad English.
This script it will in the Prefab of the Player. Script:
#pragma strict
var SistemaInventario : Inventario;
var MouseLook : MouseLook;
var PlayerAux : FPSInputController;
var MorteAux : Morte;
var Player : GameObject;
function Start () {
SistemaInventario = transform.GetComponent("Inventario");
MouseLook = transform.GetComponent("MouseLook");
MorteAux = transform.GetComponent("Morte");
PlayerAux = transform.GetComponent("FPSInputController");
}
function Update () {
if(!networkView.isMine){
return Player;
return SistemaInventario;
return MouseLook;
return MorteAux;
return PlayerAux;
return transform.position;
return transform.rotation;
}
}
Let me give you an example, if a player walking the other walks. And I want to avoid that.
Would it be right to say that you want to have a collision detection system, to avoid moving a player into the same space as the other players?
Answer by Taxen0 · Dec 17, 2014 at 11:07 AM
I'm not used to JS but you could save the player as a prefab and use Network.Instantiate to create the player when he/she connects. You could also add the variable:
var Owner : NetworkPlayer
to keep track of who the owner of the player is and set it when you instantiate the object. Now in the update function you can change the if-statement to:
if(Owner != Network.player){
enabled = false;
}
To disable the script for anyone but the owner. (you can probebly do this some better way, like disabling it in the awake function and only enable if you are the owner. for some minor performance increase)
There are many other, possibly better, ways you can take but without knowing how you are planning to set up your game im just giving some general advice.
Hope it helps!
I don't quite understand, how can I do the function of inventories return and do the action with the other players.
I'm not 100% sure what you are trying to accomplish. bit if you want to trigger an action on the other players you could use a RPC function.
I found this guide helpful for networking: http://www.palladiumgames.net/tutorials/unity-networking-tutorial/
the formatting seems to be off now, but you should be able to make out the concept.
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Multiplayer: Only see Players moving on Host 0 Answers
What is the CCU of the default Unity Networking? 1 Answer