- Home /
How to turn all lights off in prefabs
Hey guys I'm currently creating a little mobile game thanks to a series on youtube and everything goes very fine, the game is working great and everything but I have one problem.
So basically what the game does is that it chooses randomly a model from my prefabs, put it at a certain position and then does the same over and over again until you loose.
But I just saw that when I created this models (on blender) I created some lighting system on all of them and so now when they are instanciated there is too much light. I know I could simply reimport them without the lights but the problem is that I created a lot of prefabs using these models from blender and so I would have to start almost everything again. So I was wondering if there wasn't some script or a way to do so that when the prefabs are instantiated, all the lights attached to them are disabled. I also tried to go in the folder of the imported models or the first prefabs made and untick all the lights (Hemi) but when the GameObject is instantiated, the lights are still here. I think this is because I shoul make the change in the scene and then save it back in the folder but again I would have to do it all over again.
Here is the way the prefab is made :
Imported model -> First prefab -> Piece (2nd prefab) -> Segment (last prefab)
And it is the segment that is instanciated (so with all the others in it). Thanks for your help :)
Answer by Jake33011 · May 24, 2018 at 01:15 PM
I found a long but still faster way to do it. I change the intensity of the segment in the scene and then by applying it, it is saved in the folder.
Answer by Will_Croxford · May 24, 2018 at 01:35 PM
Could you try something like this, see https://docs.unity3d.com/ScriptReference/Component.GetComponentsInChildren.html: this method returns all the components of 1 type in the current object and all its child objects:
Lights = Piece.GetComponentsInChildren<Light>();
foreach (Light light in Lights)
light.enabled = false;
but sounds like you might ask question on Blender forum instead if still a problem!