Search Unity

Roll a ball and quiz (pause scene, load new and resume scene)

Discussion in 'Scripting' started by p2hari, Sep 22, 2017.

  1. p2hari

    p2hari

    Joined:
    Sep 22, 2017
    Posts:
    3
    Hello Guys,

    First I am very new to Unity and Csharp scripting. But for this question I have searched google, forums and looked into tutorials but not finding the right way to handle it. I hope this is the right thread

    Well basically I am using the Roll a ball tutorial and I am making a simple quiz game on top.

    When the ball hits 3 objects, I load the quiz scene and ask a question. On answering the question, the game should resume and if the answer is correct it should add it to the count value.

    Problem. On hitting the 3 objects I load the scene but on answering the question , when I return the game won't resume and it stays there.

    What I have done so far.
    My first approach LoadScene

    void OnTriggerEnter(Collider other)
    {
    if (concount == 3)
    {
    if (qcallcount <= 2)
    {
    concount = 0;
    qcallcount = +1;
    Time.timeScale = 0;
    SetScene();
    }
    }

    // Run the 'SetCountText()' function (see below)
    SetCountText();
    }
    }
    public void AddCount(int points)
    {
    count = +points;
    SetCountText();
    }

    private static void SetScene()
    {
    SceneManager.LoadScene("Questions");
    }

    In my questions gamecontroller

    public void AnswerButtonClicked(bool isCorrect)
    {
    if (isCorrect)
    {
    playerScore += currentRoundData.pointsAddedForCorrectAnswer;
    questionIndex++;
    ReturnToGame();
    }

    }
    public void ReturnToGame()
    {
    SceneManager.LoadScene ("Roll-a-ball")
    }

    This is loading 2 instances of the Roll a ball

    2nd Approach LoadScene Additive

    In my ontriggerenter I load the questions with LoadScene Additive
    Then I set my question display panel to false in the ReturnToGame()
    questionDisplay.SetActive(false);

    But this results in error "To many event systems , not supported " and the game does not resume and it is always paused

    3rd Approach UnloadScene

    I did Unload my scene (questions) but the game does not progress and the data is also lost.

    PS: I set Time.timescale = 1; in fixed update so that I can resume the game, I also tried Time.timescale = 1 in update, but no success.

    Please guys need your help in understanding how I can achieve this ?


    I need to collect x objects, then pop a question, Now once user answers it I have to return to roll the ball and continue. I keep doing this till all objects are cleared or if all questions are completed.
    I need to track the right answers and add to users score.
     
  2. Rob21894

    Rob21894

    Joined:
    Nov 21, 2013
    Posts:
    309
    If the purpose of the new scene is just for a quiz, you can look up the ui Canvas and activate the quiz on the specified gameobject and pause the main game, there is no need to hop between scenes and doing this you can resume with the game without having to load to other scenes
     
  3. p2hari

    p2hari

    Joined:
    Sep 22, 2017
    Posts:
    3
    Thanks Rob, but how can I resume the game, I did Time.timescale =1 in fixed update , should i do that in the update function?
    Also when you say activate the quiz, I think you mean activate the UI panel right? And have all the persistant data in the game itself?
     
  4. Rob21894

    Rob21894

    Joined:
    Nov 21, 2013
    Posts:
    309
    if you read the official Unity documentation it states this
    https://docs.unity3d.com/ScriptReference/Time-timeScale.html

    Plus there is no need to constantly set the timescale to 1 so you should do this once by calling a function once, (On a button click when the quiz is completed, or on a pause icon to unpause the game)

    Code (CSharp):
    1. public void UnpauseGame()
    2. {
    3. Time.TimeScale = 1;
    4. }