- Home /
Photon Unity Networking:How do i set it to only let players control themselves?
using UnityEngine; using System.Collections;
public class NetworkManager : MonoBehaviour {
public Camera standbyCamera;
SpawnSpot[] spawnSpots;
// Use this for initialization
void Start () {
spawnSpots = GameObject.FindObjectsOfType<SpawnSpot>();
Connect ();
}
void Connect() {
PhotonNetwork.ConnectUsingSettings( "Melting" );
}
void OnGUI() {
GUILayout.Label( PhotonNetwork.connectionStateDetailed.ToString() );
}
void OnJoinedLobby() {
Debug.Log ("OnJoinedLobby");
PhotonNetwork.JoinRandomRoom();
}
void OnPhotonRandomJoinFailed() {
Debug.Log ("OnPhotonRandomJoinFailed");
PhotonNetwork.CreateRoom( null );
}
void OnJoinedRoom() {
Debug.Log ("OnJoinedRoom");
SpawnMyPlayer();
}
void SpawnMyPlayer() {
if(spawnSpots == null) {
Debug.LogError ("WTF?!?!?");
return;
}
SpawnSpot mySpawnSpot = spawnSpots[ Random.Range (0, spawnSpots.Length) ];
GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate("Controller1", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
standbyCamera.enabled = false;
((MonoBehaviour)myPlayerGO.GetComponent("FPSInput Controller")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent ("Mouse Look")).enabled = true;
myPlayerGO.transform.FindChild("One").gameObject.SetActive(true);
}
}
I'm trying to instantiate the default controls for the free FPScontroller Asset. I would love some feedback (I should know how to do this -.-) i just need a little help. Thanks.
Your question is very unclear to me. If you are trying to get a FPS player prefab to work with a set of controls, you could import the standard controller package from Unity and have a look at how it is done there.
If you however, are trying to make sure that one set of inputs does not control all the instantiated players, you are to use the PhotonView on each client. Whenever a PhotonView is attached to an object, you can check if the object belongs to a specific client and only allow this client to control it. Whomever instantiated the object, usually owns it.
if(photonView.is$$anonymous$$ine()) {
// do sumthing specific to this client.
}
Your answer
Follow this Question
Related Questions
In Unity can you make games that have online features and how can you test it to see if it works 2 Answers
Problem with a button made 2 Answers
Multiplayer Problem 1 Answer
how to test your multiplayer game 2 Answers
A node in a childnode? 1 Answer