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:
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:
I am using C# and Unity 5 if that Helps thanks. And below is the script that the code is part of.
Code:
myPlayerGO.GetComponent<FirstPersonController>().enabled = true;
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;
}
}