- Home /
apply jpg texture to game object
I want to create a primitive and apply a pict.jpg that I have dragged into the assets folder. All the examples I've seen want you to do
myprimitive.renderer.material.mainTexture=Resources.Load("pict");//this works.
According to the docs though you can assign a texture like this
var texture : Texture;
renderer.material.mainTexture = texture;
When I load a jpg into assets it looks like it's a texture in the inspector, but
renderer.material.mainTexture="pict"; //does not work
Does resources load have to be used to apply a texture?
Thanks, Dan
Have you tried dragging it from the project view into the 'texture' slot that 'var texture : Texture' exposes in the inspector?
I have to do it dynamically as the primitives are created on the fly in the script.
Answer by BerggreenDK · Nov 26, 2011 at 12:26 PM
I think you need to load the texture into a texture object if you want to assign it later.
So create a texture variable like the docs states, then load the texture into that. Later on, when you need it, assign the variable to the mainTexture property.
how do you load pict into the texture variable? texture="pict"; ?
Your answer
![](https://koobas.hobune.stream/wayback/20220613054432im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
into which folder can i import my jpeg files so i can put some texture on a wall obj? 0 Answers
is it possible to use JPG compression on iOS export for non PVRTC textures? 0 Answers
Video texture problem? 2 Answers
Texture format for 2D Android Game 1 Answer
Is there a way to make a jpeg texture transparent for black? 2 Answers