Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Thardus · Oct 05, 2011 at 07:54 AM · textureplaneapply

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image syclamoth · Oct 05, 2011 at 07:57 AM 1
Share

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!

4 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by anszwa · Oct 05, 2011 at 08:31 AM

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.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CHPedersen · Oct 05, 2011 at 09:21 AM 0
Share

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

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

http://unity3d.com/support/documentation/ScriptReference/$$anonymous$$aterial-mainTexture.html

avatar image syclamoth · Oct 05, 2011 at 09:22 AM 0
Share

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

avatar image anszwa · Oct 05, 2011 at 10:20 AM 0
Share

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

avatar image Thardus · Oct 05, 2011 at 06:15 PM 0
Share

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.

avatar image Thardus · Oct 05, 2011 at 06:24 PM 0
Share

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?

avatar image
2

Answer by Rustam-Ganeyev · Oct 05, 2011 at 10:39 AM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by anszwa · Oct 05, 2011 at 08:07 PM

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".

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by codebaby2 · Apr 29, 2021 at 03:03 PM

Would now be:

 public GameObject go; //your plane 
 void ApplyTexture(Texture2D texture) { 
   go.GetComponent().material.mainTexture = texture; 
 }

(based on @Rustam-Ganeyev answer)

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image anszwa · Apr 29, 2021 at 03:47 PM 1
Share

Always cool to go back and see how things evolved within 10 years :)

avatar image codebaby2 anszwa · Apr 29, 2021 at 04:49 PM 0
Share

Yep, indeed :)

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

360 degree plane rotation & texture change 1 Answer

Parenting Bullet Holes? 1 Answer

Texture fade in 2 Answers

Texture3D Ignore depth mipmapping 0 Answers

Show mouse click feedback on textured 2d plane button 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges