Help in Multiplayer

Hello everyone,
So today I tried multiplayer for the first time (I’m a noob in that by the way), so I used unity’s basic multiplayer assets and followed this guys tutorial:

Everything works fine except my friend and I share the same controller. How can I make it so everytime someone connects, it spawns a different controller. Thanks.

UPDATE: Here is my error screen :

2 Answers

2

Sounds like the sort of thing you would do in OnPlayerConnected

First, I tried the code above on my first person controller, but it wouldn't work. Then I noticed that the system was telling to make a prefab of my Controller, so I did. But still I (the master of the server) am controller both me and my friend. Also we can't see each other even though I have applied the network view to my Player

–

Now I kind of understand how this works. But I still don't know how to fix my current problem. My friend and I still control the same Player and we of course can't see each other.

–

Ok so I make both AllocateViewID and on OnPlayerConnected and posted them both on my Player. Set the variable "Cube Prefab" an empty object. Now we both controll 2 different players but we still cannot see each other.

–

Alright, try this:

void OnConnectedToServer() 
{
    GameObject clone = Network.Instantiate (cubePrefab, position, rotation, 0);

    clone.AddComponent("PlayerControlScript");   //this script controls movement
    //Make your camera follow clone here
}

Make sure the “cubePrefab” only has the physical part of the character (mesh, colliders, etc) and a networkview observing the Transform component. Make sure there are NO cameras in the prefab.

This will give you a non-authorative server game where two players can see eachother.

So the cube prefab is my character but without the camera?

–

That is correct, usually the client must grab the Camera.main and set it up to follow the newly made GameObject. I usually do this by having a CameraFollow script with a public target variable.

–

Assets/Assets/Scripts/Player.cs(1,6): error CS0116: A namespace can only contain types and namespace declarations

–

What line is that on?

–

On the player

–