やりたいこと
・スコアを表示したい。
問題点
・シーンを再読み込みした際に、
NullReferenceException: Object reference not set to an instance of an object
GameControlScript.Update () (at Assets/Scripts/GameControlScript.cs:29)
というエラーが出る。
・スコアが変動しなくなる。
試したこと
null == ScoreTextで調べたところnullだった。
C#
1 2usingSystem.Collections; 3using System.Collections. Generic; 4using UnityEngine; 5using System; 6using UnityEngine.UI; 7public class GameControlScript : MonoBehaviour 8{ 9public static int result; 10public int score; 11public Text ScoreText; 12// Start is called before the first frame update void Start() 13{ 14result = 0; 15score = 0; 16DontDestroyOnLoad (this) ; 17} 18public void plus( ){ 19score++; 20} 21// Update is called once per frame 22void Update() 23{ 24result = score; 25ScoreText.text = String.Format("Score: {0:00000}", result); 26 } 27
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/01/18 14:49