toggle between gameObjects diplayed

Hi Forums

i need help,

So i have 2 .fbx’s imported from maya “Trees_oak” “Trees_pine” Each is a GROUP that has dozens of trees in it with animations and are not 1 combined mesh.

All i want is to do is toggle between these 2 groups in game using keys 1 2.

this thread was so close to the answer I’m looking for, but i’m a scripting noob and i don’t know how to link it to my groups specifically.

i know there is a problem linking groups to a variable, but i really want to avoid combining them into 1 mesh so any help would be appreciated.

Thanks in advance

Ben

Try this. Assign your two gameobjects in the inspector.

using UnityEngine;
using System.Collections;

public class VisibilityController : MonoBehaviour 
{
	public GameObject go1;
	public GameObject go2;
	
	void Start()
	{
		// Sets starting visibility
        SetVisibility(go1, true);
		SetVisibility(go2, false);		
	}
	
	void Update() 
	{
		// Listen for user input
	    if (Input.GetKeyDown(KeyCode.Alpha1)) 
		{
	        SetVisibility(go1, true);
			SetVisibility(go2, false);
	    }
		else if (Input.GetKeyDown(KeyCode.Alpha2)) 
		{
	        SetVisibility(go1, false);
			SetVisibility(go2, true);
	    }
	}
	
	void SetVisibility(GameObject go, bool isVisible) 
	{
	    // Sets the visibility of 'go' and all its children to 'isVisible'
	    Renderer[] renderers = go.GetComponentsInChildren<Renderer>();
	    foreach (Renderer r in renderers) 
		{
	        r.enabled = isVisible;
	    }
	}
}

PERFECT!!!
that worked a treat!

i see i was focusing too much on the “MeshRenderer” attribute, thats why i was so confused.

Thank you so much for your help!
your a legend!