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.
5 Answers
5function 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;
}
}
that is C#, a javascript conversion would look like this: function Start() { If(!NetworkView.is mine){ Playercontrolscript.enabled=false; } }
– PProductionsThere is a error that says, BCE0044: expecting ), found 'mine'. and BCE0043: Unexpected token: ). and lastly BCE0044: expecting :, found '='. What did I do wrong?
– Tim-AThere 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'.
– by0log1cParsing error Unexpected symbol `{' A namespace can only contain types and namespace declarations.? what am I doing worng????
– Tim-ANonono, Just go to Player Setting and do Run in Background at one of the options ![]()
function Start(){ if(!NetworkView.ismine){ MovementControlScript.enabled = false; } } Works fine for me.
– williampigmeuMovementcontrolscript needs to be changed to the name of the script that is controlling your player
– strachpr01i 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:
- create a C# script and name it IsMyPlayer.
- Copy and past the script below.
- Save and add to camera.
using UnityEngine;
using System.Collections;
public class IsMyPlayer : MonoBehaviour {
void Start()
{
if(! networkView.isMine)
{
GetComponent().enabled=false;
}
}
}
Search for tutorials on Youtube, they are a lot.
– williampigmeulook at unity's multiplayer tutorial.
– Chris12345are you using Unity's Networkng? or SmartFox or something else?
– ChesleyUnity's network
– Tim-A