- Home /
Code Wont Work?
I have this code to activate the component of my character example the movement but its not activating it? Does anyone know whats wrong with it? You can view screenshots and whatnot to get a better understanding here (click me)
void SpawnMyPlayer() {
if(spawnSpots == null) {
Debug.LogError ("WTF?!?!?");
return;
}
SpawnSpot mySpawnSpot = spawnSpots[ Random.Range (0, spawnSpots.Length) ];
GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate("soldier3rdPerson", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
standbyCamera.enabled = false;
((MonoBehaviour)myPlayerGO.GetComponent("soldierMovement")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent("MouseLook")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent("Health")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent("crouchController")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent ("skeletonToCharacter")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent ("weaponController")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent ("soldierLOD")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent ("smoothWorldPosition")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent ("soldierAnimation")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent ("soldierAim")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent ("bulletHoleProperty")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent ("gun")).enabled = true;
myPlayerGO.transform.FindChild("soldierCamera").gameObject.SetActive(true);
}
'not activating' as in you are getting null reference exceptions? Or is the code running and not doing anything? Or is the code not compiling? From the link, it looks like you were working though several issues. To start with change all of your GetComponent() calls to the generic version so you get some type checking in there:
myPlayerGO.GetComponent<soldier$$anonymous$$ovement>().enabled = true;
With this change, some issues with classes will be moved from runtime to compile time.
Your answer
Follow this Question
Related Questions
Loading spawned prefabs upon connecting to server? 1 Answer
How to synchronize disable and enabling game objects over the network? 0 Answers
How to connect to our own dedicated server using photon networking in unity?(Self-hosted) 0 Answers
Creating interactable enviornment items that are usable by all players in Multiplayer 2 Answers
send data from client to local server 0 Answers