The mobile game i'm currently creating displays the score after Game over, and reloads the level. Behind the text i'm displaying an background image prefab. The game works fine until i spawn the image.

Code:

Code:



 // set gameOver flag to true.
    public void GameOver()
    {
        GameoverText.text = "Game Over!";
        gameOver = true;
    }

    ......
    ......
    // Instantiate GameOverBGAsset1 -- the image prefab, and GameOverCanvas -- a reference to 'Canvas2', And make GameOverBGAsset1 a child of Canvas2.
    if (gameOver)
    {
                GameObject GameOverImg2 = Instantiate(GameOverBGAsset1, GameOverBGPos.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;
                GameObject GameOverCanvas = GameObject.FindGameObjectWithTag("Canvas2");
                GameOverBGAsset1.transform.SetParent(GameOverCanvas.transform);

                restartText.text = "Tap to Replay";
                scoreTextLarge.text = "Score: " + score;
                restart = true;

                break;
            }

  ....
  ....
  // restart when screen is touched
  if (restart)
  {
              tap = Camera.main.ScreenToWorldPoint(new Vector3(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y, 5));           
              if ((tap.x != 0) || (tap.y != 0) || (tap.z != 0))
              {
                Application.LoadLevel(Application.LoadedLevel);
              }
    }



When i reload the level it displays "Game Over!" -- coz it's displayed before i spawn the image -- and get stuck there. Is it actually a problem with the spawned prefab, or something else?

Thanks for any input.

P.S: This ONLY happens when i reload the level. In the first run, all the intended text and BG image is displayed as expected.