MUltiplayer

I have made a multiplayer game that makes a first person controller spawn when they press start server. Now i went on another computer to do the same and it spawned in the same spot and one person moves both of them. HELP please.

Search for tutorials on Youtube, they are a lot.

–

look at unity's multiplayer tutorial.

–

are you using Unity's Networkng? or SmartFox or something else?

–

Unity's network

–

5 Answers

5

function Start(){
if(!NetworkView.ismine){
MovementControlScript.enabled = false;
}
}

This will work fine.

Add a network view to your objects then use

Void Start(){

If(!NetworkView.is mine){

Playercontrolscript.enabled=false;

}

}

Is that C#?

–

that is C#, a javascript conversion would look like this: function Start() { If(!NetworkView.is mine){ Playercontrolscript.enabled=false; } }

–

There is a error that says, BCE0044: expecting ), found 'mine'. and BCE0043: Unexpected token: ). and lastly BCE0044: expecting :, found '='. What did I do wrong?

–

There are mistakes in these examples, guys. C# should read 'void' and not 'Void', also 'is mine' is not even a valid variable name, you meant 'isMine'.

–

Parsing error Unexpected symbol `{' A namespace can only contain types and namespace declarations.? what am I doing worng????

–

Nonono, Just go to Player Setting and do Run in Background at one of the options :smiley:

I still control both people.

–

function Start(){ if(!NetworkView.ismine){ MovementControlScript.enabled = false; } } Works fine for me.

–

I got this error,BCE0005: Unknown identifier: 'MovementControlScript'.

–

Movementcontrolscript needs to be changed to the name of the script that is controlling your player

–

So it would be fpsinputcontroller.enabled = false; right

–

i suggest only to implement this :

in the controller script :

define a variable as boolean like :

var thisOneIsMine=false;

function Start(){
 if(networkView.isMine){
  thisOneIsMine=true;
 }else{   
  thisOneIsMine=false;
 }
}

function Update(){ 
 //or FixedUpdate or whatever function u want

 if(thisOneIsMine){
  //do here all the controller implementation
  //like : inputs , speeds directions rotations 
 }
}

this is how i did it and i am new to network

Im new to scripting but i edited on of your scripts and found this worked. If you are using the FPS Controller that came with the standard assets do the following:

  1. create a C# script and name it IsMyPlayer.
  2. Copy and past the script below.
  3. Save and add to camera.

using UnityEngine;
using System.Collections;

public class IsMyPlayer : MonoBehaviour {

void Start()
{

if(! networkView.isMine)
	{
		GetComponent().enabled=false;

	}

}

}