NetworkView - control only your player?

Using this quick tutorial… How to create an online multiplayer game with Unity - Paladin Studios Ive been trying to build my own multilayer game however I cannot fix the problem of controlling all the players who are connected to the server. Ive read many questions like this but I haven’t found my answer. The tutorial I’ve been following shows how to prevent this from happened using networkview.ismine but only for a cube with a simple WASD movement script. I’m trying to do this using the FPS controller. This is my best attempt at solving this problem but it does not work, any help on this?

using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {

	private CharacterMotor characterMotor;

	void Awake(){

				characterMotor = GetComponent<CharacterMotor> ();
}


	void Update(){

		if (networkView.isMine){

			characterMotor.enabled = false;
}
		else{

			characterMotor.enabled = true;
	}
  }
}

This makes other players control the players around them not themselves, does something need to be flipped?

–

3 Answers

3

Try this:

characterMotor.enabled = networkView.isMine;
enabled = networkView.isMine;

You have basically turned it the wrong way, so when you own it you don’t control is, but when you don’t own it you control it

okay, so how do I flip this around?

–

These two lines of code should do the trick, for better performance place them in the start function since you aren't changing the owner of the objects. If you tend to use the script after remove the second line.

–

Here is what your update function should look like:

void Update(){
 
         if (networkView.isMine){
 
             characterMotor.enabled = true;//this was originally false
 }
         else{
 
             characterMotor.enabled = false;//this was originally true
     }
   }
 }

Just like Makak was saying when this is your character you can’t move it but everyone else moves everyone else’s character.

Fixed by adding these lines to NetworkManager…

((MonoBehaviour)myPlayerGO.GetComponent("MouseLook")).enabled = true;
		((MonoBehaviour)myPlayerGO.GetComponent("FPSInputController")).enabled = true;
		((MonoBehaviour)myPlayerGO.GetComponent("CharacterMotor")).enabled = true;
		myPlayerGO.transform.FindChild("Main Camera").gameObject.SetActive(true);