My code in number wizard 2d

i complete this code before the lessons finish:

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

public class number : MonoBehaviour
{
    int max = 10001;
    int min = 1;
    int guess;
    int count = 0;


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

    // Update is called once per frame
    void Update()
    {
        if (count < 7)
        {
            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                min = guess;
                guessess();
                myname();
            }

            else if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                Debug.Log("Down arrow was pressed!");
                max = guess;
                guessess();
                myname();
            }

            else if (Input.GetKeyDown(KeyCode.Return))
            {
                Debug.Log("I win");
                again();
            }
        }
        else
        {
            Debug.Log("I Lose");
            count = 0;
            again();
        }
    }

    void guessess()
    {
        guess = Random.Range(min , max);
        count += 1;
    }

    void again()
    {
        max = 10001;
        min = 1;
        guess = Random.Range(min , (max));
        Debug.Log("Welcome to Number Wizard!");
        Debug.Log("Pick a number!");
        Debug.Log("Your number must be from " + min + " to " + (max - 1) );
        myname();

    }

    void myname()
    {
        Debug.Log("you number is higher or lower or equals the " + guess);
        Debug.Log("UpArrow = higher & DownArrow = lower & Enter = Correct");
    }
}

I like the addition of only allowing 7 guesses before the player wins, but I wanted to say that I would highly recommend not using method names like ‘again’ or ‘myname’. They work fine for now but as programs get more and more complicated, as multiple people work on them, or even when you take a break and come back to it a few months later those names won’t help you determine what the process is actually trying to do in that method.

Not intended as a criticism, just a (hopefully) helpful suggestion from someone that’s been programming for 5+ years and has learned this the hard way more than once.

thank you

No problem. The whole point of this community website is to help each other out so I try to go through at least some posts each time I’m sitting down to work on my game. It can potentially help other people and it can certainly help me too (I’ve “borrowed” someone’s code more than once after seeing what they did).

One more thing I just noticed coming back here is that it’s probably a good idea to Serialize your value of 7. That way it’s easier to adjust within the Editor without needing to edit and recompile the code.

Privacy & Terms