Not Restarting properly

Hi all,

I’ve just been following the Number Wizard videos and it’s all pretty much perfect except it won’t restart properly at the end of the first round and the “Return” button seems to become inactive. Would someone by kind enough to check my code please?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NumberWizard : MonoBehaviour
{
    int max;
    int min;
    int guess;


    // Start is called before the first frame update
    void Start()
    {
        StartGame();
          

    }

    void StartGame()
    {

        max = 1000;
        min = 1;
        guess = 500;


        Debug.Log("Ahoyyyy, Welcome to number wizard me hearty!");
        Debug.Log("Polly says that It's time to think of a number, but don't tell me or 'im");
        Debug.Log("The lowest number you can pick is: " + min);
        Debug.Log("The hghest number you can pick is: " + max);
        Debug.Log("What are you waiting for, go forth Greybeard. Solve the mystery!");
        Debug.Log("Ye-arghhh Hurry up!");
        Debug.Log("Is yeee number higher or lower than 500");
        Debug.Log("Press up = High-arghh, Press Down = Low-arghh, Press Enter = Correct!! Ahoy!! Get the Rum in!");
        max = max + 1;
    }



    // Update is called once per frame
    void Update ()
    {
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            
            min = guess;
            NextGuess();
            
            Debug.Log(guess);
        }

        
           else if (Input.GetKeyDown(KeyCode.DownArrow))
        {       
           
            max = guess;
            
            NextGuess();

        }

        
        else if (Input.GetKeyDown(KeyCode.Return))
            {
                Debug.Log("Yee-arghhhh! get in mate! Let's go again. Is your number high-arghh or low-arghh than 500?");

            StartGame();
            
      }



    }
    void NextGuess()
        {
        guess = (max + min) / 2;
        Debug.Log("Is the number high-arghh or low-arghh than.." + guess);

    }
}

Hi @PopNFresh87,

Welcome to our community! :slight_smile:

Your code for the return option looks fine to me. What do you mean by “inactive”? Does the Debug.Log message appear in your console? Make sure that “Collapse” is not enable in your Console.

1 Like

Hi Nina, thank you for the reply.

The game plays perfectly the first time but when it’s time to start over. I’ve noticed the start instruction don’t appear and the “Return” key no longer responds.

UPDATE
I’ve just made sure that “Collapse” wasn’t enabled and that has fixed the problem! Thank you!!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms