Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » HELP » Help (General) » I can't enable script attached to gameObject (Photon Network)

I can't enable script attached to gameObject (Photon Network)

View previous topic View next topic Go down  Message [Page 1 of 1]

Firefox365


Member [Lv. 0]
Member [Lv. 0]
Ok so I am trying to use Photon Network and I am stuck on what seems to be simple. I am trying do enable a script, specifically the (FirstPersonControler) that is attached to the FPScontroller by default. I am doing:


Code:
 myPlayerGO.GetComponent<FirstPersonController>().enabled = true;

And it just won't work. I've tried the same code to disable a normal gameobject that is not being instantiated and I can turn scripts on and off.

I've also tried FirstPersonController as a string. As well as tried:

Code:
((MonoBehaviour)myPlayerGO.GetComponent("FirstPersonController")).enabled = true;
I am using C# and Unity 5 if that Helps thanks. And below is the script that the code is part of.

Code:
using UnityEngine;
    using System.Collections;
   
    public class NetworkManager : MonoBehaviour {
       
       SpawnSpot[] spawnSpots;
       // Use this for initialization
       void Start ()
       {
          spawnSpots = GameObject.FindObjectsOfType<SpawnSpot>();
   
          Connect ();
       }
   
       void Connect()
       {
          PhotonNetwork.ConnectUsingSettings ("Senseless 0.0.1");
       }
       //PotatoSack
       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 ("OnJoinedLobby");
   
          SpawnMyPlayer ();
       }
   
       void SpawnMyPlayer()
       {
          if (spawnSpots == null) {
             Debug.LogError ("No Spawn Points");
             return;
          }
          SpawnSpot mySpawnSpot = spawnSpots [Random.Range (0, spawnSpots.Length) ];
          GameObject myPlayerGO = (GameObject) PhotonNetwork.Instantiate ("FPSController", mySpawnSpot.transform.position , mySpawnSpot.transform.rotation, 0);
          // Enabling Components For Player
   
          //Camera
          CharacterController controller = myPlayerGO.GetComponent<CharacterController> ();
          controller.enabled = true;
          Camera camera = myPlayerGO.GetComponent<Camera> ();
          camera.enabled = true;
   
          // Mouse Look and Keyboard Components
   
          myPlayerGO.GetComponent<FirstPersonController>().enabled = true;
   
   
       
   
       }
       
    }




View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum