x


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!

more ▼

asked Apr 21 '11 at 03:47 AM

user-11839 (google) gravatar image

user-11839 (google)
16 1 1 1

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?

Apr 21 '11 at 09:20 AM Cyb3rManiak

i want to load and assign them while in play mode. So each play new assets will be created.

Apr 21 '11 at 04:06 PM user-11839 (google)
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2279
x1726
x841
x236
x223

asked: Apr 21 '11 at 03:47 AM

Seen: 2302 times

Last Updated: Apr 21 '11 at 09:32 AM