2 variables holding Renderer.materials change at the same time...
In my scene I want to add the option to change the color of a material at runtime. However, I also want to remember the original color of the materials in case the user want's to cancel the action. At any given moment only ONE object can be selected. So I defined a static variable called SelectedObject, inside the class SelectedObjectClass (JS):
public class SelectedObjectClass
{
public static var SelectedObject : GameObject;
}
In another script I control the material color editing. When an object is selected I read the Renderer.materials to TWO private variables (JS):
materials = SelectedObjectClass.SelectedObject.GetComponent.().materials;
originalMaterials = SelectedObjectClass.SelectedObject.GetComponent.().materials;
These 2 lines are only called ONCE when the object is selected. When the user changes the color, I make the changes in the "materials" variable and I assign materials back to Renderer.materials to show the change. The problem is: it seems that if I edit the color of a material inside materials, the same happens to the color of the material inside originalMaterials... So when the user cancels the edit, even though I re-assign originalMaterials to Renderer.materials, the color does not change back to the original one.
Your answer
Follow this Question
Related Questions
Edit sharedmaterial in runtime but without override the material asset 1 Answer
Material.SetColor only works in Start function? 1 Answer
Issue where Fading out Game Object causes screen to blank and then reload with gameobject gone 0 Answers
How to only access one object in array if it's index is 1 0 Answers
Skinned mesh problem 0 Answers