- Home /
Texture showing in editor but not in game
For some reason the texture I've generated in engine will happily show in the editor but when you build and run the game it just shows as one big white square, here's the relevant code:
floorTex.SetPixels(floorArray);
floorTex.Apply();
//attach texture to quad
floorQuad.GetComponent<Renderer>().material.mainTexture = floorTex;
floorQuad.GetComponent<Renderer>().material.shader = Shader.Find("Sprites/Diffuse");
byte[] bytes = floorTex.EncodeToPNG();
File.WriteAllBytes(Application.dataPath + "/../floorTexture.png", bytes);
wallTex.SetPixels(wallArray);
wallTex.Apply();
//attach texture to quad
wallQuad.GetComponent<Renderer>().material.mainTexture = wallTex;
wallQuad.GetComponent<Renderer>().material.shader = Shader.Find("Sprites/Diffuse");
bytes = wallTex.EncodeToPNG();
File.WriteAllBytes(Application.dataPath + "/../wallTexture.png", bytes);
roomTex.SetPixels(roomArray);
roomTex.Apply();
//attach texture to quad
roomQuad.GetComponent<Renderer>().material.mainTexture = roomTex;
roomQuad.GetComponent<Renderer>().material.shader = Shader.Find("Sprites/Diffuse");
bytes = roomTex.EncodeToPNG();
File.WriteAllBytes(Application.dataPath + "/../roomTexture.png", bytes);
I know the textures are generating correctly in game as I can load the .png files that were saved to disk and they're perfect. Any ideas what might be going wrong? I suspect it might have something to do with the shaders. I've explicitly included the shader in the graphics options to make sure it's loaded, any help would be greatly appreciated
Your answer
Follow this Question
Related Questions
Changing material in code doesn't update shader 3 Answers
Offset textures individually into specific world directions 2 Answers
Awesome Bump shader in Unty? 0 Answers
How to change a unique shaders property 1 Answer
Unity 1080p Video player 1 Answer