I’m trying to basically make some objects with a certain tag invisible on a key press in my controller script. I’m not sure how to search for all the game objects with a certain tag and change their visibility from the controller script. If I attach the following to the individual objects it works fine however I would rather have it controlled from one place rather than having a script attached to all the objects I want to affect.
void Update () {
if (Input.GetKey(KeyCode.Space))
{
renderer.enabled = false;
collider.enabled = false;
}
}
Like I said this works fine if attached straight to the object however how would I change it to work from one script by finding their tags then setting the renderer and collider to false. I’ve looked at the GameObject.FindGameObjectsWithTag script reference however I’m getting confused with the foreach () section. Any pointers would be appreciated.