Search Unity

MainCamera not working if I set: SetActive(true);

Discussion in 'Physics' started by AlaDyn172, Dec 21, 2014.

  1. AlaDyn172

    AlaDyn172

    Joined:
    Aug 21, 2014
    Posts:
    29
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class NetworkManager : MonoBehaviour {
    6.  
    7.     public Camera standByCamera;
    8.     SpawnSpot[] spawnSpots;
    9.  
    10.     void Start(){
    11.         spawnSpots = GameObject.FindObjectsOfType<SpawnSpot>();
    12.         Connect();
    13.     }
    14.  
    15.     void Connect(){
    16.         PhotonNetwork.ConnectUsingSettings("Distructor 1.0");
    17.     }
    18.  
    19.     void OnGUI(){
    20.         GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
    21.     }
    22.  
    23.     void OnJoinedLobby(){
    24.         Debug.Log ("OnJoinedLobby");
    25.         PhotonNetwork.JoinRandomRoom();
    26.     }
    27.  
    28.     void OnPhotonRandomJoinFailed(){
    29.         Debug.Log ("OnPhotonRandomJoinFailed");
    30.         PhotonNetwork.CreateRoom (null);
    31.     }
    32.  
    33.     void OnJoinedRoom(){
    34.         Debug.Log ("OnJoinedRoom");
    35.         SpawnMyPlayer();
    36.     }
    37.  
    38.     void SpawnMyPlayer(){
    39.         if(spawnSpots == null){
    40.             Debug.LogError ("WTF?!");
    41.             return;
    42.         }
    43.         SpawnSpot mySpawnSpot = spawnSpots[Random.Range (0, spawnSpots.Length)];
    44.         GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate("PlayerController", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
    45.         standByCamera.enabled = false;
    46.         ((MonoBehaviour)myPlayerGO.GetComponent ("FPSInputController")).enabled = true;
    47.         ((MonoBehaviour)myPlayerGO.GetComponent ("MouseLook")).enabled = true;
    48.         myPlayerGO.transform.FindChild ("Main Camera").gameObject.SetActive (true);
    49.     }
    50. }
    51.  
    In the Unity the camera on the child of CharacterController is disabled.
    So this code:
    Code (csharp):
    1. myPlayerGO.transform.FindChild ("Main Camera").gameObject.SetActive (true);
    Must work!!! But didn't work!
     
  2. AlaDyn172

    AlaDyn172

    Joined:
    Aug 21, 2014
    Posts:
    29
    Sorry. I realized which is the problem!!
    Please close the thread.
    Thanks!