- Home /
Question by
xkinginthecastlecastlex · Dec 15, 2018 at 03:35 PM ·
gameobjectgameobjectstogglemeshrenderershow
Toggle Game Objects with specific tag at runtime
Hi there,
I want to toggle Game Objects with a specific tag at runtime, therefore I am using a Game Objects with the attached script below to create an array of gameobjects which should turn the mesh off when clicking on a button (which activates the game object with the script).
Here is my code so far: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class ToggleObjects : MonoBehaviour {
public GameObject[] visibleList;
void OnTriggerEnter(Collider other) {
if (visibleList == null) {
visibleList = GameObject.FindGameObjectsWithTag("wall");
}
foreach (GameObject visible in visibleList) {
visible.GetComponent<MeshRenderer>().enabled=false;
}
} }
Unfortunately my Object is still visible at runtime. Does anyone know how to fix that?
Many thanks in advance!
Comment