I am having a problem with the Photon Networking. Here is my problem, I took the “Code_enabler”, “Code_game”, and “Code_menu”, from the demo worker scene, and put them in my fps project. Then I put the “First Person Character Controller” in the player prefab parameter of “Code_game”, and everything works fine except the players can’t see each other. Someone Please help.
Instead of copy and pasting stuff from other demos, better start and work through the basic tutorial to understand how things are interacting.
The Marco Polo tutorial should give you a good start:
I hope with that you will find the missing link ![]()
I have made it a lot farther, but some of the code doesn’t work even when I copy and paste. Do u have any ideas? Thanks for helping me out. ![]()
Sorry but “some code doesn’t work” is too vague to help.
Some of the code only works if you setup relations between components correctly. Example: In the Inspector, you must drag and drop a prefab’s script component to the PhotonView’s “Observed” field. Otherwise the PhotonView will only observe the translation, not the script. Stuff like that might go wrong outside of code.
oh sorry
, I have made it down through to the “Fight for Control” part, but then this code doesn’t work:
void OnJoinedRoom()
{
GameObject monster = PhotonNetwork.Instantiate(“monsterprefab”, Vector3.zero, Quaternion.identity, 0);
→ CharacterControl controller = monster.GetComponent();
→ controller.enabled = true;
→ CharacterCamera camera = monster.GetComponent();
→ camera.enabled = true;
}
It says that I need to fix compile errors, is this helpful enough? I am truly thankful for your help.
If there are compile errors, the output command will point you to the exact line that’s broken (in most cases). So it should more or less guide you to the cause of the issue. Try double-click the message in the Editor’s console, too.
It’s essential for your progress that you learn to read those compiler messages and try to make sense of that. Else you get stuck too often (compile errors happen several times per hour to me).
I have already spent about half an hour on it, but u are probably right, so I will continue to try. ![]()
I got rid of the compile errors and now just 2 things(I hope
) are keeping me from my dream of a multiplayer fps. Problem 1: only the person that joins the room can see the other players, not the one that created it. Problem 2: the one that can see the other player moves the other player along with his. I don’t know if that made sense(I am not very good at explaining things).
This is most likely a control issue. This happens when you use the same prefab to spawn your own character and those representing the remote players. Remember: You put some scripts on the avatar to move it around but the very same scripts run when you instantiate the character for someone else.
In this case the scripts will constantly try to control all characters.
You need to make them behave by checking “photonView.isMine” and disabling some of them. Read the Marco Polo tutorial again. Especially the part “Fight For Control”.
‘photonView.isMine’ doesn’t seem to exist, am I not importing something I should? I am new to Unity3d if you couldn’t tell, I have only been doing it for about a week and a half. ![]()
The property photonView is only available if your script extends from Photon.MonoBehaviour.
Else use GetComponent().
How do I assign to the PhotonView the script of an object instead of the transform, if I even can?
Select the script component itself and drag / drop it into the observed field.
or from the script:
//Add PhotonView component
PhotonView view=gameObject.AddComponent<PhotonView>();
//Add a new PhotonNetworkPlayer script and assign it to the observed field.
view.observed=gameObject.AddComponent<PhotonNetworkPlayer>();
or if you have already your PhotonView on the gameObject attached.
//Get PhotonView component and PhotonNetworkPlayer component and add the PhotonNetworkComponent to the observed
//field. This will give an error if there is no PhotonView or PhotonNetworkPlayer attached to the gameObject.
PhotonView.Get(gameObject).observed=gameObject.GetComponent<PhotonNetworkPlayer>();
or via GetComponent like tobiass said.
//Get PhotonView that is attached to the gameObject
PhotonView view= gameObject.GetComponent<PhotonView>();
//Get PhotonNetworkPlayer that is attached to the gameObject
PhotonNetworkPlayer networkPlayer=gameObject.GetComponent<PhotonNetworkPlayer>();
//Is PhotonView and PhotonNetworkPlayer null?
if(view networkPlayer){
view.observed=networkPlayer; // No it is not null, so add the PhotonNetworkPlayer to the observed field of the PhotonView.
}
Thank you both, sorry for taking so much of your time tobiass!