Hi
How could I convert a Texture2D to a Material?
Material myMaterial = www.texture as Material;
button.GetComponent<Image> ().material = myMaterial;
Thank You
Hi
How could I convert a Texture2D to a Material?
Material myMaterial = www.texture as Material;
button.GetComponent<Image> ().material = myMaterial;
Thank You
Please, somebody could help me. Please.
Materials and textures are different things.
Materials are instances of shaders.
Textures are imported bitmaps with certain import conditions applied.
Materials MAY have slots that can accept texture references.
Some materials MAY accept more than one texture (i.e., diffuse, normal, specular, etc. textures).
ok, so can I apply a texture 2D on my button ? What is the best way to do it? Please
There’s a lot of great information on various ways of doing things here: Learn
I like how a lot of your threads show how you seem to think casting is the solution to everything.
string myGameString "I would love to have a game where I can press WASD to move and click the mouse to shoot zombies. Yeah, I would love to have zombies. Zombie and dragon. Please unity"
MonoBehaviour myScript = myGameString as MonoBehaviour;
How great would it be if it was that easy.
More seriously thought, to change the texture of a button, you don’t have to access material properties.
You have to change the source image of the image component attached to the button.
#include UnityEngine;
#include UnityEngine.UI;
void Start(){
myButton.GetComponent<Image>().sprite = myOtherSprite;
}
Here is a simple way of how you can convert a texture to a material;
• Import your desired texture to you unity project
• Create a new material
• In the new plain material you just created, there will be a feature called ‘Albedo’ in the inspector panel of the new material (located at the beginning).
• Select the circle at the right side of the ‘Albedo’ writing
• Select the texture you imported
•Save
Please don’t necro threads.