-
-
Save knoff/8bb75160b17d3f75924e to your computer and use it in GitHub Desktop.
Unity 3D. Create material at runtime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Material material = new Material (Shader.Find("Diffuse")); // Common names are: "Diffuse", "Bumped Diffuse", | |
// "VertexLit", "Transparent/Diffuse" etc. | |
material.SetTextureScale("_MainTex", new Vector2(100,0)); // "_MainTex" is the main diffuse texture. | |
// This can also be accessed via mainTextureScale property. | |
// "_BumpMap" is the normal map. | |
// "_Cube" is the reflection cubemap. | |
material.mainTexture = Resources.Load("Floor") as Texture2D; // Texture resource name | |
AssetDatabase.CreateAsset(material,("Assets/Resources/material.mat")); // material path in assets folder | |
floor.renderer.material = material; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The last line "floor.renderer.material = material;", no floor defined in your code.
Can you supply the full code file for this? And maybe an example YouTube of you using it?
I ended up creating the following script. It seems easy enough to use a color picker for a mesh.