D
D
DarkMill2020-12-11 17:24:38
C++ / C#
DarkMill, 2020-12-11 17:24:38

Null reference exception? Why might she be there?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class MainMenu : MonoBehaviour
{
[SerializeField] int money;
public int total_money;
public Text moneyText;

private void Start()
{
money = PlayerPrefs.GetInt("money");
total_money = PlayerPrefs.GetInt("total_money");
}

public void ButtonClick()
{
money++;
total_money++;
PlayerPrefs.SetInt("money", money);
PlayerPrefs.SetInt("total_money", total_money);
}

public void ToAchievemnts()
{
SceneManager.LoadScene(1);
}

void Update()
{
moneyText.text = money.ToString();
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-12-11
@freeExec

So you haven't assigned a variable, so here it is.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question