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
Share
Go down
Member [Lv. 0]
Member [Lv. 0]
Posts : 1
Points : 1219
Rep : 0
Join date : 2015-03-23
View user profile

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

on Mon Mar 23, 2015 1:58 pm
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;
   
   
       
   
       }
       
    }




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