dynamically set material

	newCube.GetComponent(setSpriteMaterial).setSpriteMaterial([B]selectedMaterial+"CubeTex"[/B]);

right, I’m unsure how to set a material depending on a variable- I have “selectedMaterial” which is “Stone/Wood/etc”- all those Texture2D’s exist, for example StoneCubeTex,WoodCubeTex, etc, however how do I implement this- the highlighted part returns errors- what is the correct syntax?

note: setSpriteMaterial is a simple function I created that accepts a Texture2D

If setSpriteMaterial accepts a Texture2D, then you should give it a Texture2D and not a string, which is what you are doing.

If you have some Texture2D available as variables, pass one of those. If your textures are in the Resources folder and you want to load them on demand, use Resources.Load.