Unity3d运行时动态修改材质

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

		var resMat = Resources.Load("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;

		} 
	}

  

转载于:https://www.cnblogs.com/mrblue/p/4629517.html

你可能感兴趣的:(Unity3d运行时动态修改材质)