- Home /
How to set false components to true?
Alright so this has had me stumped for about a week or two. Well I'm trying to make my game online, so what I had to do for the networking player was have them start with the components below false. I try to set them true with my C# script but it is simply not working. I have no idea why. I'm not sure if you aren't able to set a component True after it's already been set to false or what. If you could please tell me what I'm doing wrong that would be fantastic!
~Thanks in advance
~A bit of my code just in case you need to see it~
((MonoBehaviour)myPlayerGO.GetComponent("FPSInputController")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent("MouseLook")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent("CharacterMotor")).enabled = true;
myPlayerGO.transform.FindChild("Main Camera").gameObject.SetActive(true);
}
Answer by KiraSensei · Jan 06, 2015 at 08:40 AM
With the code you have, the only thing that can go wrong is
myPlayerGO.transform.FindChild("Main Camera").gameObject.SetActive(true);
Because if the main camera is not active, it will not be found. Since you want to activate it, I suppose it is not yet activated :)
So you need to do this :
var mainCamera:GameObject;
And valuate in the inspector this variable with the corresponding game object in the scene.
And then :
mainCamera.SetActive(true);
For the other lines of code, everything should be find if myPlayerGO is already an activated game object. If not, you need to activate it first like the main camera.
Thanks that solved part of my problem :) However all of the other scripts are still false
GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate ("PlayerController", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
That is what my variable "myPlayerGO" equals. I'm not sure if the script isn't understanding that myPlayerGO is apart of Player Controller or something (Sorry have a hard time explaining these types of things) But yeah if you could give me a sample script to get my online network up and running I would be super grateful.
Also I'd like to thank you again for taking the time to help me with this.
Does your player controller prefab contains a mouse look script and an character controller script ?
Yes it does. I mean looking at that is the only reason I know that everything remains false
Wait never$$anonymous$$d! :D:D:D:D:D I finally fixed it! there was nothing wrong with my code or anything like that but I guess the script didn't like the order I had everything in lol. Thanks so much for the help though :)
Ok, cool ! Please accept the answer to close the question byt ticking the check icon on the left side :)