Mesh Disable

From Unify Community Wiki
Jump to: navigation, search

A very simple MeshDisable script for disabling all the meshes of children of a game object( this does not disable the , attach it to a game object , and right click the script. From their you need to get the meshes , and then select TurnOff or TurnOn . Call the public functions Render Enable or RenderDisable to disable the meshes during gameplay .

This can be useful in games where you need to temporarily disable the renders of a large amount of objects

C# - MeshDisable.cs

using UnityEngine;
using System.Collections;
 
public class MeshDisable : MonoBehaviour {
public Transform Holder ;
	public Renderer[] RU ;
	public Renderer[] RU2 ;
	// Use this for initialization
	void Start () {
 
	}
 
 
 
 
	// Update is called once per frame
	void Update () {
 
	}
 
	[ContextMenu("TurnOn")]
public	void RenderEnable(){
	foreach(Renderer er in RU){
			if(er)
		er.renderer.enabled = true ; 	
		}
	foreach(Renderer er2 in RU2){
			if(er2)
		er2.renderer.enabled = true ; 	
		}
	}
 
[ContextMenu("TurnOff")]
public	void RenderDisable(){
 
	foreach(Renderer re in RU){
		if (re)
			re.renderer.enabled = false ;		
		}
	foreach(Renderer re2 in RU2){
		if(re2)
			re2.renderer.enabled = false ;		
 
		}
 
	}
 
	void ChildMeshes(){
 
		int i = 0 ; 	
		System.Array.Resize(ref RU2,Holder.childCount);
	foreach( Transform child in Holder){
 
	RU2[i] = child.gameObject.GetComponent<Renderer>();		
		i++;
	}}
 
[ContextMenu("GetMeshes")]
 
 
 
void GetMesh(){
		if(Holder)
		ChildMeshes();
 
		int i = 0 ; 	
		System.Array.Resize(ref RU,transform.childCount);
	foreach( Transform child in transform){
 
	RU[i] = child.gameObject.GetComponent<Renderer>();		
		i++;
		}	
 
 
	}
 
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox