Camera and control problems with network!

I have made a simple fps game, and networked is using the Unity Networking Example.

A player can create a server, but there is a problem.

When another player connects to this server, via direct connect, their camera and movement controls switch, so when they move they do not see the effects, the other player does.

I have attached to the FPSWalker and MoveLook scripts networkView.isMine, but this does not help!

Please I need help ASAP!

The solution Tetrad has provided has been asked for in UnityScript, so here you go:

@SerializeField
var behavioursEnabledOnLocalClientsOnly : Behaviour[];

@SerializeField
var behavioursEnabledOnRemoteClientsOnly : Behaviour[];

@SerializeField
var gameObjectsEnabledOnLocalClientsOnly : GameObject[];

@SerializeField
var gameObjectsEnabledOnRemoteClientsOnly : GameObject[];

function OnNetworkInstantiate(msg : NetworkMessageInfo) {
    if (!networkView.isMine) {
        name += "(remote)";
    }

    for ( var behaviour in behavioursEnabledOnLocalClientsOnly) {
        behaviour.enabled = networkView.isMine;
    }

    for ( var behaviour in behavioursEnabledOnRemoteClientsOnly) {
        behaviour.enabled = !networkView.isMine;
    }

    for (var go in gameObjectsEnabledOnLocalClientsOnly) {
        go.active = networkView.isMine;
    }

    for (var go in gameObjectsEnabledOnRemoteClientsOnly) {
        go.active = !networkView.isMine;
    }
}

For more information on how to convert a C# solution to JavaScript, see: networking issues, camera changes / converting answer in C# to UnityScript

Grokking how things are supposed to work with multiplayer takes a bit of getting used to. Here's a little script I wrote that can help get a handle on a few things.

using UnityEngine;
using System.Collections;

public class PlayerNetworkInit : MonoBehaviour
{
    [SerializeField] Behaviour[] behavioursEnabledOnLocalClientsOnly;
    [SerializeField] Behaviour[] behavioursEnabledOnRemoteClientsOnly;
    [SerializeField] GameObject[] gameObjectsEnabledOnLocalClientsOnly;
    [SerializeField] GameObject[] gameObjectsEnabledOnRemoteClientsOnly;

    void OnNetworkInstantiate( NetworkMessageInfo msg ) 
    {
        if( !networkView.isMine )
        {
            name += "(remote)";
        }

        foreach( Behaviour behaviour in behavioursEnabledOnLocalClientsOnly )
        {
            behaviour.enabled = networkView.isMine;
        }
        foreach( Behaviour behaviour in behavioursEnabledOnRemoteClientsOnly )
        {
            behaviour.enabled = !networkView.isMine;
        }

        foreach( GameObject go in gameObjectsEnabledOnLocalClientsOnly )
        {
            go.active = networkView.isMine;
        }
        foreach( GameObject go in gameObjectsEnabledOnRemoteClientsOnly )
        {
            go.active = !networkView.isMine;
        }
    }
}

So let's say you have a prefab that's your player that has FPSWalker, MouseLook, a Camera, etc all underneath it. Put that script on it and think about each behaviour and game object that should only be on local clients or remote clients. For example, the MouseLook and FPSWalker scripts would go under "behaviours enabled on local clients only" and the first person camera would be under "game objects enabled on local clients only". Chances are you'll want your players to have rigidbodies on them, and you'll have a NetworkRigidBody script that you only want on the remote player.

If you just instantiated the players as-is, you would get issues where you would have two cameras active, and both local and remote players would default to the first main camera in the scene and there would be issues with having multiple scripts reacting to player input.

There were too many cameras on the game. So i destroyed the unnecessary cameras.

Where does one go to find information on behaviours? A search of the scripting reference turned up nothing, and the manual is not searchable, so not much help.

I attached the .js version of the script to my prefab (a vehicle with a camera and controls), and increased the size of the “Behaviours Enabled On Local Clients Only” property to 2. I could drag the camera node onto one of the elements, which cleared up the multiple camera issues, but when using the drop-down method, the assets tab is empty, and the scene tab only lists assets that I’ve put into the scene. I’ve found no way to get a script into the field. I’m assuming because a behaviour has to actually be defined somewhere?

i have the same problam but where do i put the if(networkview.isMine() {}?