- Home /
Multiplayer Help
I have a multiplayer game with 2 first person controllers. The problem I am having is that I control both of them. Is there a way to separate them?
Answer by nastasache · Sep 03, 2012 at 02:10 PM
You have to use something like that:
if (networkView.isMine) {
// Activate movement controllers
} else {
// Deactivate movement controllers
}
See http://forum.unity3d.com/threads/97471-Problem-with-networkView.isMine
if (networkView.is$$anonymous$$ine) {
GetComponent(CharacterController).enabled = true; GetComponent($$anonymous$$ouseLook).enabled = true; GetComponent(FPSInputController).enabled = true; GetComponent(CapsuleCollider).enabled = true; GetComponent(Health).enabled = true;
} else {
GetComponent(CharacterController).enabled = false; GetComponent($$anonymous$$ouseLook).enabled = false; GetComponent(FPSInputController).enabled = false; GetComponent(CapsuleCollider).enabled = false; GetComponent(Health).enabled = false;
}
That's what I have and it still doesn't work. :( did I do it wrong? Thanks in Advance!
I don't know why it's not working. Did you followed http://unity3d.com/support/resources/example-projects/networking-example ?. See there SpawnPrefab.js and ThirdPersonInit.js: - Network.Instantiate (prefab) then, "OnNetworkInstantiate" do: if (networkView.is$$anonymous$$ine) { ...
Btw: Actually, the player movement are not by CharacterController or CapsuleCollider (I think you have to not disable these) but by FPSInputController & $$anonymous$$ouseLook & Character$$anonymous$$otor; or ThirdPersonController if you have it; Disable/enable only these latest.
function OnNetworkLoadedLevel () {
if (networkView.is$$anonymous$$ine) {
GetComponent($$anonymous$$ouseLook).enabled = true; GetComponent(FPSInputController).enabled = true; GetComponent(Health).enabled = true; GetComponent(Character$$anonymous$$otor).enabled = true; GetComponent(CharacterController).enabled = true; GetComponent(EnemyHealth).enabled = true; GetComponent(NetworkView).enabled = true; } else {
GetComponent($$anonymous$$ouseLook).enabled = false; GetComponent(FPSInputController).enabled = false; GetComponent(Health).enabled = false; GetComponent(Character$$anonymous$$otor).enabled = false; GetComponent(CharacterController).enabled = false; GetComponent(EnemyHealth).enabled = false; GetComponent(NetworkView).enabled = false;
} }
I still control both people. What am I doing wrong?
Answer by wyvernfist · Mar 07, 2013 at 10:57 AM
Have the PlayerOwner prefab and PlayerProxy prefab. Put all controls on PlayerOwner, and have PlayerOwner instantiate a PlayerProxy to all other players with NetworkView controlling its movement.