- Home /
Material Disappeared after destroyed
So, I have have a prefab that has a material on it. I got a script that changes the color of the material.
public Color [] colorArray;
public GameObject [] objectArray;
GameObject theObject;
public void ChooseObject (int theNumber)
{
theObject = objectArray [theNumber];
}
public void ChangeAppleColor (int theNumber)
{
theObject.renderer.material.color = colorArray [theNumber];
theObject = null;
}
I am currently using Unity 4.6, and using the new UI button thing, with the click () function to access my change color script. So, when I press play, I'll change the color of my apple, and start to play my game. I use instantiate () to make apple clones, and once they are below like -20y, they'll get destroyed. When I press the play button again, which is end the playing, my material on my apple prefab disappears! The missing reference exception warning comes out! Can someone explain this?
Your answer
Follow this Question
Related Questions
Material leak workaround? 5 Answers
Do I need to manually destroy material/model instances that are lazily copied? 2 Answers
How do I make UI buttons to destroy a gameObject in certain area (after a line position)? 1 Answer
Material doesn't have a color property '_Color' 4 Answers
clicking to change material click again to change back 3 Answers