I have a prefab that instantiates and this prefab has a child. The question is how do I access the script of the child(the nested prefab in the parent which was the original instantiated prefab) to change a bool from true to false. Any help would be appreciated. Thank you.
BTW I need to be able to change it while it is running while the game is in play.
I am a bit confused by what you have said. Are you instantiating a prefab which has a child object, and that child object has a script on it that you want to change a variable on? If you have reference to the object that was created(instantiated at run time). Then you can get reference to the child script by gameObject.GetComponentInChidren();
If the variable you are trying to change is public then you can change it.
Will give you a reference to the script you want to gain access to.
scriptExample.myBool = false;
Will change the value of the boolean you are trying to change. If its public.
Can you post code on how you are instantiating your object, and the script with the boolean you are trying to change. And the script that is trying to change the boolean?
I just noticed that the last one you posted is a static method. A few possible things. Is the script for the child on the child itself or is it somewhere else, you may be accessing it but not affecting the right thing. Does the script of the child have an existing PUBLIC bool. I realize that’s really simple but there are a ton of errors in my own programs I’ve fixed just going back and reading it again and realizing I had 1 little thing out of place.
I think your script is getting a little too complex. when you’re accessing the child you should be able to just have a public bool on the child. In addition make the script of the child static and public. you won’t need to worry about accessing it unless the parent is instantiated.
So maybe something like this
public static ChildPrefab child;
public bool on = false;
then in whatever script you’re using to change the child bool could be something like this