I need a script to disable/hide one child game object inside a parent when you exit a trigger collider.

Alrighty, so for some context:

I have a First Person Controller. It’s children are Graphics and Main Camera. The First Person Controller has an inactive script called Rain Creator on it. The game starts. I move into ‘Area1’ and that causes Rain Creator to turn on. Rain Creator makes a clone of a prefab in my Assets (Heavy Rain) and then makes it a child of First Person Controller. I leave ‘Area1’ and the Rain Creator script turns off, but Heavy Rain (Clone) is still a child of First Person Controller.

So I want to add to the Rain Creator script that when I leave ‘Area1’ the child object ‘Heavy Rain(Clone)’ is hidden so that when I walk back into ‘Area1’ it will unhide that same child object. I do NOT want to delete/destroy the child object, because if I do the Rain Creator script will not make another when it gets re-activated.

Is there a way for a ‘ForEach’ loop to only target one child object and then disable it? I think that’s what I need to do but I can’t figure out how. C# preferred but I could probably get javascript to work as well.

P.S. These suggested tags are terrible for this post >_>

You should change a little your logic: instead of enabling/disabling RainCreator, activate/deactivate heavyRain (create it if necessary when entering Area1) - like this:

using UnityEngine;
using System.Collections;

public class RainCreator: MonoBehaviour {

    public GameObject heavyRainPrefab; // heavy rain prefab

    private GameObject heavyRain;
      
    void OnTriggerEnter(Collider other){
        if (other.name == "Area1"){ // entering Area1:
            if (heavyRain){ // if heavyRain already exists...
                 heavyRain.SetActive(true); // activate it
            } else { // if doesn't exist yet, create it:
                 heavyRain = Instantiate(heavyRainPrefab, transform.position, transform.rotation) as GameObject;
            }
        }
    }

    void OnTriggerExit(Collider other){
        if (other.name == "Area1"){ // leaving Area1:
            heavyRain.SetActive(false); // deactivate heavy rain
        }
    }
}

You need Transform

Transform imageaux = gameobjaux.transform.Find("Image"); imageaux.gameObject.SetActive(false);