x


Assigning textures in project panel to materials dynamically or via editor scripts

Is it possible to assign textures in project panel to materials via editor scripts, or at runtime?

more ▼

asked Sep 17 '11 at 03:15 AM

ina gravatar image

ina
3.3k 492 547 597

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Correct me if I misunderstood the question, but I think this may be what you're trying to achieve?

    public Texture colorMap;//Assign this in inspector
    public Texture colorMap2;//Assign this in inspector

//The next lines will assign the above textures to the gameobject's material texture:
    if (condition)
    {
    gameObject.renderer.material.mainTexture = colorMap;
    }
    else if (!condition)
    {
    gameObject.renderer.material.mainTexture = colorMap2;

    }

Depending on the shader you may have access to other textures as well through scripting, such as normal maps, etc.

more ▼

answered Sep 17 '11 at 05:36 AM

Krayt gravatar image

Krayt
31 2 2 4

this would work if you can reference your material, but i am not sure how to reference the material if it is just in the project pane (not yet in hierarchy)

Sep 17 '11 at 06:48 AM ina
(comments are locked)
10|3000 characters needed characters left
Your answer
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:

x386
x374
x347
x273
x3

asked: Sep 17 '11 at 03:15 AM

Seen: 814 times

Last Updated: Sep 17 '11 at 06:48 AM