I’m quite new to Unity and currently have the issue that I can’t add a texture to my procedurally generated plane:
function Start () {
//Create landscape
var plane : GameObject = GameObject.CreatePrimitive(PrimitiveType.Plane);
plane.transform.position = Vector3(0.0, 0.0, 0.0);
plane.renderer.material.mainTexture = Resources.Load("planeTex");
}
I created a graphic that is 1024x1024 and saved it as .jpg and than dragged this image into my “assets → materials” folder in unity. At least this is what I gathered in other articles.
Considering the articles this should be a simple task but somehow the texture is not visible (the plane is white).
Any help is appreciated (maybe I’m missing a basic information about textures or something like this).
It would be much better if you had the texture as a variable on your script. This would allow you to assign it in the inspector and ensure that it also gets assigned to your material.
– Benproductions1Resources.Loadmay returnnullif the asset is not found.I tried that as well, but the texture was still not visible. Do you maybe have a link to an example?
– christianstrangYou mean like this? var plane : GameObject = GameObject.CreatePrimitive(PrimitiveType.Plane); plane.transform.position = Vector3(0.0, 0.0, 0.0); var mainTex : Texture = Resources.Load("planeTex"); plane.renderer.material.mainTexture = mainTex;
– christianstrangno, more like this: var texture:Texture2D; function Start() { //plane code plane.renderer.material.mainTexture = texture; } This is the standard for inspector assigned variables and is preferred over any dynamic resource loading because of the increased speed it provides.
– Benproductions1