Players Control Other Player

This is my character control script. But it only controls the other player. Everything is perfect but for some reason you control each other not yourself. (And I know my scripts terrible I through it togethor quickly)

pragma strict
var projectile: Transform;
var gun : Transform;

 var firerate = 50;
 var rounds = 25;
 
 var speed = 2;
  var run = 25;
  
//var health = 100;


 var ammotake = false;
private var hit: RaycastHit;
 function OnGUI () {
    GUI.Label (Rect (10, 75, 100, 20), "Rounds: " + rounds);
	//GUI.Label (Rect (10, 100, 100, 20), "Health: " + health);
	
	
	if(ammotake == true){
	GUI.Label (Rect (10, 150, 200, 20), "Right click to take ammo");
	}
}


function Update () {
if(networkView.isMine) {
      if (Input.GetKeyDown(KeyCode.H)){
     if(Screen.lockCursor == true){
	 Screen.lockCursor = false;
	 }
	 else if(Screen.lockCursor == false){
	 Screen.lockCursor = true;
	 }
		}
}		
		
var fwd = transform.TransformDirection (Vector3.forward);

    if (Physics.Raycast (transform.position, fwd,hit, 2)){

if(hit.transform.tag == "ammo"){
ammotake = true;
if(Input.GetMouseButtonDown(1)){
	
	 Network.Destroy(hit.collider.gameObject);
 rounds += 10;
 }
 
 
	}


 }
 else{
 ammotake = false;
 }
 
          if(networkView.isMine) {
		 
		
		
      if (Input.GetKey(KeyCode.W)){
    transform.Translate(Vector3.forward * Time.deltaTime * speed);
		}
		// if (Input.GetKey(KeyCode.Space)){
    //rigidbody.AddForce(Vector3.up * 15);
		//}
		if (Input.GetKey (KeyCode.A)){
transform.Translate(Vector3.left * Time.deltaTime * speed);
		}
		if (Input.GetKey (KeyCode.S)){
transform.Translate(Vector3.back * Time.deltaTime * speed);
		}
		if (Input.GetKey (KeyCode.D)){
transform.Translate(Vector3.right* Time.deltaTime * speed);
		}
		
		
	if(Input.GetMouseButton(0)){
	if(firerate > 50){
fire();
}

    }
    }
firerate += 1;

}
function fire(){
if(networkView.isMine) {

if(rounds >= 1 ){

 var shoot = Network.Instantiate(projectile, gun.position, gun.rotation, 0);

 firerate = 0;
 rounds -=1 ;
 }
 }
 }

who owns the networkviews ?

Thanks for Answering! The instanted player has a network view on them. Maybe there getting mixed up? Is there a way to fix that?

Edit: I checked who owns the network and they both say “0” Also you see your own character but you control the other players character.

If i’m not mistaken, 0 means server.
So the server owns the networkviews and has control over all the objects.

Ok, how can I make it so each computer owns there player? The code I used for multyplayer is in Unity 3d’s third person multyplayer example by the way. Also (there are 2 players(1 server 1 player)) the player controls the server and the server controls the player. But they see there player, not the one there controlling. So it might be a camera issue… but I doubt that.

You could start by reading the manual : http://docs.unity3d.com/Documentation/ScriptReference/30_search.html?q=network

The concerned methods are :

The code to spawn the character is just this

function OnNetworkLoadedLevel ()
{
	Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
}

Edit: also my player has a network view, and then the camera thats a child of the player also has a network view (just to make sure I have it on both)

The method ‘OnNetworkLoadedLevel’ is not an engine method so it must be an RPC one, but your missing the RPC attribute then.
And in what context is the RPC executed and by who.

I have an empty gameobject which has this script on it

var playerPrefab : Transform;

function OnNetworkLoadedLevel ()
{
	Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
}

function OnPlayerDisconnected (player : NetworkPlayer)
{
	Debug.Log("Server destroying player");
	Network.RemoveRPCs(player, 0);
	Network.DestroyPlayerObjects(player);
}

Bump? Anyone? The basic networking script is form here : http://unity3d.com/support/resources/example-projects/networking-example.html