xxxxxxxxxx
[SerializeField] Material material;
void WhenYouWantTheMaterialToChange
{
GetComponent<Renderer>().material = material;
}
xxxxxxxxxx
using UnityEngine;
public class MaterialChanger : MonoBehaviour
{
public Material newMaterial;
void Start()
{
// Assuming you have a reference to the renderer component where the material should be changed
Renderer renderer = GetComponent<Renderer>();
if (renderer != null && newMaterial != null)
{
// Change the material at runtime
renderer.material = newMaterial;
}
}
}
xxxxxxxxxx
public Material material1;
gameObject.renderer.material = material1;
// Change the Color of the GameObject
material1.color = Color.red;