Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » HELP » Help (General) » Bug after reloading the scene

Bug after reloading the scene

View previous topic View next topic Go down  Message [Page 1 of 1]

1 Bug after reloading the scene on Thu Dec 24, 2015 11:29 pm

KasunL


Member [Lv. 0]
Member [Lv. 0]
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.

View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum