- Home /
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?
Answer by Krayt · Sep 17, 2011 at 05:36 AM
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.
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)
Your answer
Follow this Question
Related Questions
Grab Image/texture from MTL file and apply to a game object 1 Answer
Cannot make another prefab of same model 3 Answers
Multiple Tiling Textures in the Same Material 1 Answer
Accessing multiple texture materials on objects 3 Answers
Tiling textures in material without changing the material. 0 Answers