• 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 /
  • Help Room /
avatar image
0
Question by karthikveeramani · Jan 22, 2017 at 05:31 AM · texturecolorscripting beginnerplane

Switching plane texture through script

Complete newbie here. I have two planes, with albedo set to green and white. I have a texture (png, 16-bit, 256x256, it just has an alphabet with transparent pixels all around) that I'd like the plane to show at runtime, when an event happens. After searching the internet including this forum, I did this:

Material newMaterial = (Material) Resources.Load("AnotherMaterial", typeof(Material)); planeObject.GetComponent < MeshRenderer > ().material = newMaterial;

I can see that when the event triggers, the color of the plane changes to a pinkish color, but not to the texture. Same thing happens on either plane. I also tried not using my png texture, but making "AnotherMaterial" have a different color. Result is the same.

Could someone explain how to do this right?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by karthikveeramani · Jan 22, 2017 at 05:46 AM

OK I figured out the answer shortly after my post. Leaving it here in case someone else has the same trouble.

It looks like Resources.Load() works only if the asset is under a folder called Resources (under Assets directory). So I made Resources/Materials folder, and changed my load to

Material newMaterial = (Material) Resources.Load("Materials/AnotherMaterial", typeof(Material));

and that worked. I didn't realize that the "pink color" that showed up earlier was due to the material not being found - I had assumed I'd see an error in that case.

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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

105 People are following this question.

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

Related Questions

Prevent Stretching of Image on Material Assigned to a 3D Plane? 0 Answers

Texture color values changing slightly despite compression settings 1 Answer

What is color and what is material (in the context of gameobject)? 1 Answer

Need help to combine shaders, is this possible? 0 Answers

I export blender file to fbx for unity.. 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges