Unity3d运行时动态修改材质

void Start () {
		const string MainTexVariableName = "_MainTex";
		var renders = gameObject.GetComponentsInChildren<Renderer>();

		var resMat = Resources.Load<Material>("CharacterThrough");

		foreach (var render in renders)
		{
			var oreginalMaterial = render.sharedMaterial;
			var currentRender = render;

			var newMat = new Material(resMat);

			newMat.SetTexture(MainTexVariableName, oreginalMaterial.GetTexture(MainTexVariableName));

			currentRender.material = newMat;

		} 
	}

  

posted @ 2015-07-08 11:05  MrBlue  阅读(13362)  评论(0编辑  收藏  举报