- Home /
Cache materials into List (or array) and restore from cached List?
Hey guys, I have a character which consists of several game objects each with different material. When my character is hit I want to flash all it's pieces with white color. And after short time return to materials there were before
I grab all renderers and materials into arrays:
void Start()
{
renderers = GetComponentsInChildren<Renderer>().ToList().FindAll(el => !((el is ParticleSystemRenderer)||(el is TrailRenderer) )).ToArray();
materials = GetComponentsInChildren<Material>().ToList().FindAll(el => !((el is ParticleSystemRenderer)||(el is TrailRenderer) )).ToArray();
}
To replace materials with dedicated Flash material (plain white color)
foreach (var el in renderers)
{
if (flashMaterial != null)
rend.material = flashMaterial;
}
so the question is: How can I restore original materials after such replacement?
Comment
Your answer
Follow this Question
Related Questions
Copy values between two classes in two lists. 1 Answer
Problem with arrays in a list 1 Answer
How to prevent a list from being cleared at runtime? 2 Answers
Undo/back system using a List/Array 2 Answers
what are Lists? 1 Answer