using UnityEngine;
using System.Collections;
public class NetworkManager : MonoBehaviour {
public Camera standbyCamera;
SpawnLocation[] SpawnLocations;
void Start () {
SpawnLocations = GameObject.FindObjectsOfType<SpawnLocation>();
Connect ();
}
void Connect () {
PhotonNetwork.ConnectUsingSettings("Version 0.0.1");
}
void OnGUI() {
GUILayout.Label ( PhotonNetwork.connectionStateDetailed.ToString());
}
void OnJoinedLobby() {
Debug.Log ("JoinedLobby");
PhotonNetwork.JoinRandomRoom();
}
void OnPhotonRandomJoinFailed() {
Debug.Log ("RandomJoinFailed");
PhotonNetwork.CreateRoom( null );
}
void OnJoinedRoom() {
Debug.Log ("JoinedRoom");
InitialSpawnPlayer();
}
void InitialSpawnPlayer() {
if(SpawnLocations == null){
Debug.LogError ("No spawns available, Go fix it");
return;
}
SpawnLocation mySpawnLocation = SpawnLocations[Random.Range(0, SpawnLocations.Length)];
GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate("PlayerMainA1", mySpawnLocation.transform.position , mySpawnLocation.transform.rotation, 0);
standbyCamera.enabled = false;
//multiple components need to be activated/enabled after the player joined
((myPlayerGO.FindChild("FPS_Player")).GetComponent("FPSPlayer")).enabled = true;
((MonoBehaviour)myPlayerGO.FPS_Player.GetComponent("Horizontal Bob")).enabled = true;
((MonoBehaviour)myPlayerGO.FPS_Player.GetComponent("Vertical Bob")).enabled = true;
((MonoBehaviour)myPlayerGO.FPS_Player.GetComponent("Ironsights")).enabled = true;
((MonoBehaviour)myPlayerGO.FPS_Player.GetComponent("FPSRigid Body Walker")).enabled = true;
((MonoBehaviour)myPlayerGO.FPS_Player.GetComponent("Drag Rigidbody")).enabled = true;
((MonoBehaviour)myPlayerGO.FPS_Camera.GetComponent("Smooth Mouse Look")).enabled = true;
((MonoBehaviour)myPlayerGO.FPS_Weapons.GetComponent("Player Weapons")).enabled = true;
((MonoBehaviour)myPlayerGO.FPS_Weapons.GetComponent("Gun Sway")).enabled = true;
myPlayerGO.FPS_Camera.transform.FindChild("Main Camera").gameObject.SetActive(true);
}
}
What am I doing wrong when I am enabling the components at the end?
I’m getting errors like
“Assets/Scripts/NetworkManager.cs(48,92): error CS1061: Type UnityEngine.Component' does not contain a definition for
enabled’ and no extension method enabled' of type
UnityEngine.Component’ could be found (are you missing a using directive or an assembly reference?)”
and
“Assets/Scripts/NetworkManager.cs(57,28): error CS1061: Type UnityEngine.GameObject' does not contain a definition for
FPS_Camera’ and no extension method FPS_Camera' of type
UnityEngine.GameObject’ could be found (are you missing a using directive or an assembly reference?)”