One player breaks the other

Hi! I have been using the Photon plugin for Unity, and have been impressed by how easy it was to set up. But I am having a problem. I can connect to multiplayer fine (Cloud server), but when my friend comes on, I am reset to the start point, unable to move, and he is free to move. I can't see him, but he can see me at the start point. What have I done wrong? Here is my script(Used from a YouTube video):

[code2=csharp]using UnityEngine;
using System.Collections;

public class NetworkManager : Photon.MonoBehaviour {

static public string userName = "ashjack";
static public bool connecting = false;
static public bool connected = false;

// Use this for initialization
void Start () {
connecting = false;
connected = false;

}



void OnGUI() {
if(!connecting) {
GUILayout.BeginArea( new Rect(Screen.width/2 - 100, 0, 200, Screen.height) );
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();


GUILayout.Space(20);
if(userName.Length > 0 && GUILayout.Button("Multi-Player")) {
connecting = true;
PhotonNetwork.ConnectUsingSettings("alpha 0.1");
}

GUILayout.Space(20);
if(userName.Length > 0 && GUILayout.Button("Single-Player")) {
connecting = true;
PhotonNetwork.offlineMode = true;
PhotonNetwork.CreateRoom(null);

}

GUILayout.FlexibleSpace();
GUILayout.EndVertical();
GUILayout.EndArea();
}
else if(!connected) {
GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString());
}
}

void OnJoinedLobby() {
PhotonNetwork.JoinRandomRoom();
}

void OnPhotonRandomJoinFailed() {
PhotonNetwork.CreateRoom(null);
}

void OnJoinedRoom() {
connected = true;
SpawnPlayer();
}

void SpawnPlayer() {
GameObject player = PhotonNetwork.Instantiate( "Player", transform.position, Quaternion.identity, 0 );
}

}[/code2]

Also, this movement script might play a part in this:

[code2=csharp]using UnityEngine;
using System.Collections;

public class Movement : Photon.MonoBehaviour {

public float maxWalkSpeed = 10.0f;
public float maxTurnSpeed = 100.0f;
public Animator anim;
public PhotonView pv;

void Start()
{

}

void Update () {


if (pv.isMine) {
var walkSpeed = Input.GetAxis ("Vertical") * maxWalkSpeed;
var turnSpeed = Input.GetAxis ("Horizontal") * maxTurnSpeed;

transform.Translate (0, 0, walkSpeed * Time.deltaTime);

transform.Rotate (0, turnSpeed * Time.deltaTime, 0);

if (walkSpeed > 5) {
anim.SetFloat("Speed", 1f);
}
if(walkSpeed > 5&&Input.GetKeyDown(KeyCode.LeftShift)){
anim.SetFloat("Running", 1f);
}
if(walkSpeed > 5&&Input.GetKeyUp(KeyCode.LeftShift)){
anim.SetFloat("Speed", 1f);
anim.SetFloat("Running", 0f);

}
if(walkSpeed < 1){
anim.SetFloat("Running", 0f);
anim.SetFloat("Speed", 0f);
}
}
}

}[/code2]

Comments

  • I can't debug your code right now but I solved the very same issue in the Marco Polo Tutorial. I think I disabled the input scripts on the prefab, then enabled only the one on the GO that I network-instantiated myself.

    http://doc.exitgames.com/photon-cloud/M ... 0Tutorials
  • Sorry for taking ages to reply, I thought that this topic wouldn't be answered. I tried disabling the scripts in the movement script in the prefab, and have tried enabling it after, but the problem still occurs even before I enable the script(which does nothing).

    Is the problem possibly that I instantiate the camera with the player, which results in multiple cameras in the game?
  • Yes, that could be a problem, depending on how you do it.
    I think you should be able to check that in the hierarchy. Look out for cam objects.