- Home /
Enabling a component on initialization/Photon Cloud Problem
So in my multiplayer game each time I initialize a player when they join a room I need to enable certain components in that instance, and not in others like its camera, and movement. What has been happening is when I do something like move my mouse around on one client it also moves around on the other. I would like some way to stop this. Here is my code now.
void OnJoinedRoom()
{
GameObject player = PhotonNetwork.Instantiate("ClientPlayer", Vector3.zero, Quaternion.identity, 0);
CharacterMotor controller = player.GetComponent<CharacterMotor>();
MouseLook camera = player.GetComponent<MouseLook>();
camera.enabled = true;
}
well, that snippet of code will only affect the newly-created object.
You'd have to be actively sending your mouse information between clients, or using global information, or broadcasting ins$$anonymous$$d of sending targeted function calls, to make them move in sync. Are the clients on the same computer? What does your "everyone is doing this but only one should" code look like?
I have tested it on two computers with the same result. Photon servers use this thing called photonview to broadcast player position and other things to the other clients. I have it set up to where it will just broadcast the whole first person controllers transforms (ClientPlayer) to every client. You can read about it the photonview section of this tutorial : http://doc.exitgames.com/photon-cloud/$$anonymous$$arco_Polo_Tutorial/#cat-tutorials
Also here is a picture of how I have it set up: WW
I don't have personal experience with Photon; all I can do is point to the "Fight for Control" bit of that tutorial. Try pausing your game while it's running and exa$$anonymous$$ing all the existing player object; see if perhaps their components are enabled when they shouldn't be.
Ugh...I gone through the tutorial multiple times and I have messed with the components while it is running with the same result no matter what I do. It is weird that once two players are in the room one client controls the other but not itself and vice versa.
I also have this question that 2 players will control the other when they in one room. Do you figure out what the problem is?