The error:
NullReferenceException: Object reference not set to an instance of an object
SlotMachine.Update () (at Assets/SlotMachine.cs:35)
The code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SlotMachine : MonoBehaviour
{
public bool slotHandlePressed;
public bool isSpinning;
public int rowOneNum;
public int rowTwoNum;
public int rowThreeNum;
public Text rowOneText;
bool changeText;
void Start()
{
rowOneText = GetComponent<UnityEngine.UI.Text>();
}
void Update()
{
if (changeText == true)
{
rowOneText.text = "TEST";
}
}
void OnMouseDown()
{
if (slotHandlePressed && isSpinning == false)
{
isSpinning = true;
RandomNumberGenerator();
}
}
void RandomNumberGenerator()
{
int rowOneNum = Random.Range(1, 9);
int rowTwoNum = Random.Range(1, 9);
int rowThreeNum = Random.Range(1, 9);
changeText = true;
}
}
When I place the code to change the text in the Start function it works fine however anywhere else and it does not work.