- Home /
Question by
MARTYELECBREN · Apr 13 at 02:44 PM ·
gameobjectmeshtoggletoggle button
Change from Mesh Render Toggle To GameObject Toggle
I am trying to toggle between two game objects in a scene however the way the script is set up is it is currently toggling between mesh renders, normally this would be fine however I need to add sounds that toggle on and off with the game objects, any Ideas how I would go about editing this?
public void toggleBuilding(bool ExistingBuildingBool, bool ProposedBuildingBool)
{
// Toggle mesh colliders and renderers for the first building
if (ProposedBuildingStructure != null)
{
meshChildren = ProposedBuildingStructure.GetComponentsInChildren<MeshRenderer>();
foreach (MeshRenderer mesh in meshChildren)
{
if (ExistingBuildingBool)
{
wpc.buildingMain = mesh.gameObject.transform;
}
mesh.enabled = ExistingBuildingBool;
ProposedBuildingStructureGO.SetActive(true);
if (mesh.GetComponent<MeshCollider>() != null)
{
mesh.GetComponent<MeshCollider>().enabled = ExistingBuildingBool;
ProposedBuildingStructureGO.SetActive(false);
}
}
// Toggle mesh colliders and renderers for the second building
meshChildren = ExistBuildingStructure.GetComponentsInChildren<MeshRenderer>();
foreach (MeshRenderer mesh in meshChildren)
{
if (ProposedBuildingBool)
{
wpc.buildingMain = mesh.gameObject.transform;
}
mesh.enabled = ProposedBuildingBool;
if (mesh.GetComponent<MeshCollider>() != null)
{
mesh.GetComponent<MeshCollider>().enabled = ProposedBuildingBool;
ExistingBuildingStructureGO.SetActive(true);
}
}
Comment