There is a strange thing going on in my latest project!
When i get the color variable of meshrenderer.material.color and do not even assign it to anything, the material of the prefab from which i instantiated the object gets removed AFTER stopping the game in test mode. Now the strangest thing of all is that i use the same meshrenderer.material.color on another gameobject and this gives no problem at all. I’m truly clueless, any help is appreciated.
[EDIT]
a Video of the problem: http://www.youtube.com/watch?v=KXlh2FbGu4s
[/EDIT]
Some snippets from my code:
//////////////////////////////////////
// WoordenGM.cs
// if this meshrenderer.material.color is called, after the scene is closed the material is removed from the symbol prefab!!
// (see bug ->)
//////////////////////////////////////
public GUIStyle symbolButtonStyle, symbolLabelStyle;
void OnGUI()
{
if (gameManager.play !gameManager.win)
{
if (showSymbolString) { DrawSymbolString(); }
gameManager.menu.DrawMainBackground(buttonMenuHeight);
drawSymbols(buttonMenuHeight);
gameManager.menu.DrawTopbar(gameManager.menu.selectedGame.Name, 120, true);
gameManager.menu.DrawStatusBar(gameManager.menu.selectedGame.Name);
}
else if (gameManager.play gameManager.win)
{
drawWinScreen();
}
}
/// <summary>
/// Draw the name of the dragging symbol
/// </summary>
public void DrawSymbolString()
{
GUIContent content = new GUIContent(activeSymbol.name);
Rect rect = new Rect(Screen.width / 2 - 200, 200, 400, 60);
// bug -> removes materials from prefab when assigning the matrial color to textcolor
symbolLabelStyle.normal.textColor = activeSymbol.GetComponent<MeshRenderer>().material.color;
GUI.Label(rect, content, symbolLabelStyle);
//symbolLabelStyle.normal.textColor = Color.black;
}
//////////////////////////////////////
// Symbool.cs
// If only this meshrenderer.material.color exists, the material wil not be removed after playing scene
//////////////////////////////////////
public void Destroy()
{
if (explode != null)
{
((ParticleSystem)Instantiate(explode, transform.position, transform.rotation)).startColor = ((MeshRenderer)transform.GetComponent<MeshRenderer>()).material.color;
Destroy(gameObject);
}
else
{
Destroy(gameObject);
}
if (woord != null)
{
woord.symbool = null;
}
}