- Home /
Question by
SecondMouse · Mar 09, 2014 at 04:55 PM ·
photongetcomponentsetactiveenable
Enable My Script on Spawn
I get an error when trying to disable scripts on my player when it spawns (so it doesn't interefere with other spawned players) using Photon Networking. The Character Controller activates fine, but it won't activate the Animation component or my RPG scripts, or my GUI script.
Here is my code (taken from the Multiplayer FPS in Unity 3d on quill18creates' YouTube channel):
void SpawnMyPlayer() {
if(spawnSpots == null) {
Debug.LogError ("WTF?!?!?");
return;
}
SpawnSpot mySpawnSpot = spawnSpots[ Random.Range (0, spawnSpots.Length) ];
GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate("Player", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
standbyCamera.SetActive(false);
myPlayerGO.transform.FindChild("Main Camera").gameObject.SetActive(true);
((MonoBehaviour)myPlayerGO.GetComponent("Animation")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent("RPG_Animation")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent("RPG_Controller")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent("Character Controller")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent("GUIStatusPlayer")).enabled = true;
How can I enable my scripts when the player spawns?
Comment