i need a script to put an albedo into a material

Hi guys ! Please help me, i follow the first tutorial and i write this script

using UnityEngine;
using System.Collections;

public class ExampleBehaviourScript : MonoBehaviour
{
void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
GetComponent ().material.color = Color.red;
}
if (Input.GetKeyDown(KeyCode.G))
{
GetComponent().material.color = Color.green;
}
if (Input.GetKeyDown(KeyCode.B))
{
GetComponent().material.color = Color.blue;
}
}
}

It steel work ok, but i need to change the albedo texture, not just the color, I need to put my texture into the material via script, it is possible ?79166-script-example.jpg

Yes it is possible. Lets say you have two variables (I will make them public so they can be set through the inspector) like this

public Sprite sprite;
public Material material;

You can then set the Albedo image using the following code

if ((sprite != null) && (material != null))
{
    material.SetTexture("_MainTex", sprite);
}

Thank you Thank you Thank you Thank you Thank you !!! Tonight i will test it :smiley: