- Home /
Dynamic Material & Textures
Ok,
I need to create a script that creates a new material that assigns itself an image from my resources folder as a texture.
So far i gather that i need to:
function Update ()
{
var count = 0;
while(count != 4)
{
var material = new Material (Shader.Find("Specular"));
AssetDatabase.CreateAsset(material,("Assets/Resources/tMat" + count + ".mat"));
count++;
}
}
make a new material, name it procedurally, but im having trouble implementing resources.load to assign the image.
Then i need to instantiate a prefab that has one of these procedurally created materials attached. Lots of trouble with this:
theX = a; //counter to move it
obj = GameObject.Find("arch");
obj.Instantiate(obj, Vector3 (theX, 0, 0), Quaternion.identity);
I just dont know how to assign a material with
renderer.material.MainTexture = Resources.Load("whatever")
Any pointers would help, im stuck!
Just to be clear - are you talking about doing it in play mode? Or do you want to create these materials in your project for the long haul?
i want to load and assign them while in play mode. So each play new assets will be created.
Answer by KNOFF · Feb 19, 2015 at 04:41 AM
I made gist: Create material at runtime
I'll update it if found something new with this theme.
Your answer
Follow this Question
Related Questions
Material Resource will not load when Resources.Load is called 2 Answers
Loading textures from file 1 Answer
Need help with creating dynamic textures. 1 Answer
Dynamicaly Creating A Plane With A JPG Material ... 2 Answers
Changing shared texture at runtime without affecting project settings? 1 Answer