- Home /
Question by
NorthGateGames · Apr 23, 2014 at 04:04 AM ·
basic
Photon Networking Prefab help
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);
}
}
The player Prefab isn't loading the Components that are attached Thus making everyone control eachother in-game.... please post a quick and simple answer. I'm not an expert but it would be nice if i could do it without linking to another article (AGAIN) Thanks!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613143353im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Shooting at ground 1 Answer
Not working gui buttons 1 Answer
Can somebody help me out with a jumpscare? (Like from the game "Slender") 1 Answer
Any one knows how this is done? 1 Answer