In my Unity Project I try to highlight some object with some self-made material. Unfortunately the codes I found does not work.
The following script is added to three different GameObjects:
Renderer[] rend_ThisObject;
Material white, red;
void Start()
{
// I tried the following two code parts:
white = Resources.Load<Material>("White");
white = Resources.Load("Material/White.mat", typeof(Material)) as Material;
red = Resources.Load<Material>("Red");
red = Resources.Load("Material/Red.mat", typeof(Material)) as Material;
}
void Update()
{
foreach (var child in rend_ThisObject)
{
child.material = blinkObject ? white : red;
}
}
If I run the project the game objects with the script appears in pink and do not blink.
If I change the Material white, red; to public Material white, red; it works fine. What do I have to change to get the materials from my assets/resources/material folder?