Networking Script Controls the Opposite Player

I have made two netowrking scripts so far. here is the first.

using UnityEngine;
using System.Collections;
using System;

public class MPBase : MonoBehaviour 
{

    public string connectToIp = "127.0.0.1";
    public int connectPort = 25000;
    public bool useNAT = false;
    public string ipaddress = "";
    public string port = "";

    string playerName = "<NAME ME>";

    void OnGUI()
    {
        if (Network.peerType == NetworkPeerType.Disconnected)
        {
            if (GUILayout.Button("Connect"))
            {
                if (playerName != "<NAME ME>")
                {
                    Network.useNat = useNAT;
                    Network.Connect(connectToIp, connectPort);
                    PlayerPrefs.SetString("playerName", playerName);
                }
            }

        if (GUILayout.Button("Start Server"))
        {
            if (playerName != "<NAME ME>")
            {
                Network.useNat = useNAT;
                Network.InitializeServer(32, connectPort);

                foreach (GameObject go in FindObjectsOfType(typeof(GameObject)))
                {
                    go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
                }
                PlayerPrefs.SetString("playerName", playerName);
            }
        }
            playerName = GUILayout.TextField(playerName);
            connectToIp = GUILayout.TextField(connectToIp);
            connectPort = Convert.ToInt32(GUILayout.TextField(connectPort.ToString()));
        }
        else
        {
            if (Network.peerType == NetworkPeerType.Connecting) GUILayout.Label("Connect Status : Connecting");
            else if (Network.peerType == NetworkPeerType.Client)
            {
                GUILayout.Label("Connection Status : Client!");
                GUILayout.Label("Ping to Server: " + Network.GetAveragePing(Network.connections[0]));
            }

            else if (Network.peerType == NetworkPeerType.Server)
            {
                GUILayout.Label("Connection Status : Server!");
                GUILayout.Label("Connections: " + Network.connections.Length);
                if (Network.connections.Length >= 1)
                    GUILayout.Label("Ping to Server: " + Network.GetAveragePing(Network.connections[0]));
            }

            if (GUILayout.Button("Disconnect"))
                Network.Disconnect(200);

            ipaddress = Network.player.ipAddress;
            port = Network.player.port.ToString();
            GUILayout.Label("IP Address: " + ipaddress + ":" + port);
        }
    }

    void OnConnectedToServer()
    {
        foreach (GameObject go in FindObjectsOfType(typeof(GameObject)))
        {
            go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
        }
    }
}

This was written in C#. Now here is the next, also written in C#

using UnityEngine;
using System.Collections;

public class SpawnScript : MonoBehaviour 
{
    public Transform player;

    void OnServerInitialized()
    {
        SpawnPlayer();
    }

    void OnConnectedToServer()
    {
        SpawnPlayer();
    }

    void SpawnPlayer()
    {
        Network.Instantiate(player, transform.position, transform.rotation, 0);
    }

    void OnPlayerDisconnected(NetworkPlayer player)
    {
        Network.RemoveRPCs(player);
        Network.DestroyPlayerObjects(player);
    }

    void OnDisconnectedFromServer(NetworkDisconnection info)
    {
        Network.RemoveRPCs(Network.player);
        Network.DestroyPlayerObjects(Network.player);
        Application.LoadLevel(Application.loadedLevel);
    }
}

And I also added this code to my MouseLook script and FPS Script (JavaScript)

function Start()
{
    if(!networkView.isMine)
    {
        enabled = false;
    }
}

function Whatever() {
if(networkView.isMine){
//do whatever 
}
}

The only problem is that when I connect with two clients, Player1 controls player 2's character and Player2 controls Player1's. Please leave a response or help me one on one by contacting me at fiercemodz@gmail.com

Hey. Check if setting "observed" field in your "network view" component to none (instead of a supposed Transform:GameObject that might be there, would help. there's a possibility that you want to use the networkView just for RPC calls and, by mistake, you're updating everyone's position this way.

At least that's what happened to me before.

Your need is documented in the official netwokring example. What you basically need is to get the 'others' controller scripts and disable them in each client, once they spawn. However this is only a small part of the whole solution, which is pretty complicated. link text

Hey, I’m not sure if you have solved this yet or not, but I had a similar problem. If yours is what mine was, all you’ll need is to create a .js file and put it on the camera. This is all you need in that file.
function Awake() {

if(networkView.isMine){
    camera.enabled = true;
}else{
	camera.enabled = false;
}

}