I have created a Toggle with Unity UI and added a script to it.
So the point is, that my game instantiated a number of objects with a specific tag. I want to find them and toggle on/off their mesh renderer.
I have come so far with SetActive. However, it hides the object completely and there is a problem with unhiding it. Will be happy to receive any help!
public class ToggleRaycast : MonoBehaviour
{
public Toggle m_Toggle;
public void OnMouseDown()
{
if (m_Toggle.isOn)
{
GameObject[] raycasters2 = GameObject.FindGameObjectsWithTag("Raycaster");
foreach (GameObject raycaster2 in raycasters2)
{
raycaster2.SetActive(true);
}
}
else
{
GameObject[] raycasters2 = GameObject.FindGameObjectsWithTag("Raycaster");
foreach (GameObject raycaster2 in raycasters2)
{
raycaster2.SetActive(false);
}
}
}
}