if (GameObject.Find(“name”).renderer.material.name == “mat_name”)
{
Application.LoadLevel(“Game_Over”);
}
else
{
do smthng…
}
Event “do somthng” never happens
if (GameObject.Find(“name”).renderer.material.name == “mat_name”)
{
Application.LoadLevel(“Game_Over”);
}
else
{
do smthng…
}
Event “do somthng” never happens
There are three possible reasons that come to mind:
Update()
function, you don’t need to worry about that. Otherwise, you will need to call the function manually. For example: if the function is called “GameOver()”, you can call it by simply putting “GameOver();
” somewhere in the code)if
statement is always true, and the else
statement is never executed. (The else
statement will only run if GameObject.Find("name").renderer.material.name
is not "mat_name"
, or if the object “name” is not found)You may wish to debug the code:
//If you are using JavaScript, the 'void' keyword would be 'function' instead
//I only use "GameOver()" as an example
void GameOver ()
{
Debug.Log("GameOver function was called");
if (GameObject.Find("name").renderer.material.name == "mat_name")
{
Debug.Log("Game over!");
Application.LoadLevel("Game_Over");
}
else
{
Debug.Log("Not over yet...");
}
}
else
statement was reached.Based on this information, you should be able to identify the problem.
Note that you can click the “Collapse” button in the console to avoid spam.
It turns out that material name is something like “mat_name (Instance)” o_O