Before updating to Windows 10 you may need to return your Pro license. More information here

Applying a texture to a plane

Hi, I'm trying to apply a texture to a plane. I imported the psd file as an asset but I don't know what to do with it. I've searched the tutorials but I can't figure out how to apply a texture to a 2d plane. It would be nice if I could know how to do it at runtime AND how I can apply it before running the program.

more ▼

asked Oct 05, 2011 at 07:54 AM

avatar image

1 8 7 8

Have you tried experimenting? It's really pretty easy. As in, drag and drop easy. To the point at which, if you can't manage that, I'm not sure if you'd be able to use anything I could tell you about doing it in scripts!

Oct 05, 2011 at 07:57 AM syclamoth
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

Hi, in the editor mode is it very easy, you only need to create the plane, and put the texture on it with drag and drop from the project folder into the scene view plane. Unity will automatically creates a Material folder for you with the material on the object. The other way is to create the material by yourselve (Assets-Create-Material) and put the texture on it in the inspector, drag and drop the material in the scene view like before or assign it in the hirarchy to the plane. An advice, dont work with photoshop files, they are very large. Convert the psd files to an other format like png or jpeg before importing it to unity.

If you want to change texture while runtime, the easiest way is to put a script on the plane with following code (JaveScript):

 public var myTexture : Texture;
 renderer.material.SetTexture("_MyTexture", myTexture);

If you want to change the material only under a certain conditions and not at startup, for example key input, you have to put the sceond line in the update function and ask for it in an if condition.

more ▼

answered Oct 05, 2011 at 08:31 AM

avatar image

118 13 15 17

Good advice. :) But remember that this only works if the shader he selects for the material has a property called "_MyTexture". Most of them don't actually, for example the default diffuse shader's texture is called "_MainTex" in its shader code.

To begin with, it's probably better to use the builtin property, Material.mainTexture, it does the same as calling SetTexture with "_MainTex" as the property you're setting, see here:


Oct 05, 2011 at 09:21 AM CHPedersen

To be fair, doing it that way is slower, but for the purposes is much easier to use.

Oct 05, 2011 at 09:22 AM syclamoth

Oh, ok thank you, you are right! Dont think of this when i answered the question^^

Oct 05, 2011 at 10:20 AM anszwa

If I drag and drop the texture onto the scene, it doesn't show up at runtime. I tried putting the script code you mentioned into Javascript (I tried maintexture and setTexture) and neither of them make the texture appear on the plane at runtime.

Oct 05, 2011 at 06:15 PM Thardus

Actually, it works fine when I drag and drop but I can't get it to appear using code. When I use Javascript, the default texture "none" is applied. Do I have to somehow set the main texture in the settings somewhere?

Oct 05, 2011 at 06:24 PM Thardus
(comments are locked)
10|3000 characters needed characters left

Don't know anything about psd, but i apply texture on maya's plane the following way:

 public GameObject go; //your plane
 void ApplyTexture(Texture texture) {
   renderer.material.mainTexture = texture;

How to apply texture before running: put your prefab into scene. You'll see it's mesh renderer in inspector view. Then create new material with your texture and put your new created material to that mesh renderer.

more ▼

answered Oct 05, 2011 at 10:39 AM

avatar image

Rustam Ganeyev
181 60 50 56

(comments are locked)
10|3000 characters needed characters left

Ok i dont know why it is still not working, but here are some reasons I can imagine what could be the problem. Dont know how much experience you have with unity, but that are realy basics.

Make sure that your camera is seeing the plane in the game view. There for at best use the 2-3 layout you can select in the upper right corner. Then also deselect the "maximize on play" button to see the scene view also while running the game in editor. If there is the texture on the plane, you have the wrong camera position or the side with the back face culling of the plane at the front.

Drag and drop the plane not only somewhere in the scene, drop it it directly on the plane. You should see the texture on the plane even while holding the mouse and be over the object.

If you use the script, put it the same way on the plane, and then you have to drag an drop the texture over the empty variable in the hirarchy where is standing "none" at default. You could also go to the little icon left of "none" and select it from the list. Somehow or other at the and there should be the name of the texture instead of "none".

more ▼

answered Oct 05, 2011 at 08:07 PM

avatar image

118 13 15 17

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Oct 05, 2011 at 07:54 AM

Seen: 32366 times

Last Updated: Oct 05, 2011 at 08:07 PM