Joesp
1
I am trying to access the spotlight to turn Light.enabled = true or = false, how can I do that given that I have access to the gameObject Flashlight?
Light lightComponent = flashlightGameObject.transform.Find(“Spotlight”).GetComponent();
lightComponent.enabled = true ;
You could do
Light light = flashLightGameObject.GetComponentInChildren<Light>();
if(light != null)
{
light.enabled = true;
}
This way its only guaranteed to get a light in the children, and it will avoid null reference errors.