it showing an error in line no 24 on my visual studio as NullReferenceException: Object reference not set to an instance of an object
NumberWizard.StartGame () (at Assets/scripts/NumberWizard.cs:24)
here is my code, which is already provided in your lectures resource folder:-
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class NumberWizard : MonoBehaviour
{
[SerializeField] int max;
[SerializeField] int min;
[SerializeField] TextMeshProUGUI guessText;
int guess;
// Use this for initialization
void Start()
{
StartGame();
}
void StartGame()
{
guess = (max + min) / 2;
guessText.text = guess.ToString(); // this part causing the error
max = max + 1;
}
public void OnPressHigher()
{
min = guess;
NextGuess();
}
public void OnPressLower()
{
max = guess;
NextGuess();
}
void NextGuess()
{
guess = (max + min) / 2;
guessText.text = guess.ToString(); // this part causing the error
}
}
please help me to solve this. Although game is running as per expected logic but this error keep appearing on my unity console while i’m running the game.