Skip to content

Only restarts once? #4

@SteveLunny

Description

@SteveLunny

Hi there

My code seems to match yours. I can play the game, and restart it once but after that it doesn't respond anymore. Any idea what might be wrong

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

public class NumberWizard : MonoBehaviour
{
int maxGuess;
int minGuess;
int guess;

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

void StartGame()
{
    maxGuess = 1000;
    minGuess = 1;
    guess = 500;
    Debug.Log("Welcome to Number Wizard, eh!");
    Debug.Log("Pick a number from 1 to 1000! Do eeet!");
    Debug.Log("Don't go higher than " + maxGuess);
    Debug.Log("Don't go lower than " + minGuess);
    Debug.Log("Tell me if your number is higher or lower than my guess, " + guess);
    Debug.Log("Push UP if your number is higher. Push DOWN if you number is lower. Push ENTER if it's correct!");
    maxGuess = maxGuess + 1;
}


// Update is called once per frame
void Update()
{

    if (Input.GetKeyDown(KeyCode.UpArrow))
    {
        minGuess = guess;
        NextGuess();
    }

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

    }

    else if (Input.GetKeyDown(KeyCode.Return))
    {
        Debug.Log("I got it! I'm amazing xo.");
        StartGame();
    }
}

void NextGuess()
{
    guess = (maxGuess + minGuess) / 2;
    Debug.Log("Is it higher or lower than " + guess);
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions