Activate Deactivate all GameObjects with same Tag

  • i am struggling to activate deactivate gameobjects any one correct the solution

using UnityEngine;
using System.Collections;
public class objectenabler : MonoBehaviour {
// Use this for initialization
public string obl;
private GameObject A;
void Start () {

}
void OnTriggerExit (Collider other){
    if (other.gameObject.tag == "player") {
            A = GameObject.FindGameObjectsWithTag (obl);
        foreach (GameObject B in A) {
            A = gameObject.SetActive (true);
        }
        }
    }
// Update is called once per frame
void Update () {

}

}

if they’ve been deactivated that function isn’t going to find them… if these objects are known at the Start and aren’t dynamically created; cache an array of them using this function in the Start function, then iterate over that array not a new one.

If they’re dynamically created… add them to a list as they are created, iterate over that list.

1 Like