unity 初心者です。
現在、ブロック崩しゲームを作成しているのですが、ブロックが消えたときにスコアを、UPするスクリプトを組んでいるのですが、上手く表示されません。
using
1using System.Collections.Generic; 2using UnityEngine; 3using UnityEngine.UI; 4 5public class GameScore : MonoBehaviour { 6 7 public Text ScoreLabel; 8 9 public int score; 10 11 // Use this for initialization 12 void Start () { 13 } 14 15 // Update is called once per frame 16 void Update () 17 { 18 score = GetComponent<Ball_move>().point; 19 ScoreLabel.text = "Score : " + score; 20 } 21} 22 23コード
public
1{ public int point; 2・・・略・・・ 3 void OnTriggerEnter(Collider c) 4 { 5 if (c.gameObject.tag == "yoko_filed") 6 { 7 x_dir = x_dir * -1; 8 } 9 if (c.gameObject.tag == "filed") 10 { 11 y_dir = y_dir * -1; 12 } 13 if (c.gameObject.tag == "block") 14 { 15 y_dir = y_dir * -1; 16 17 point = point + 100; 18 } 19} 20コード
実行すると、下記エラーが表示されます。
NullReferenceException: Object reference not set to an instance of an object
GameScore.Update () (at Assets/GameScore.cs:19)
ご教授の程、よろしくお願いいたします。
![
空のGameObjectにGameScore.csをアタッチして、ScoreLabelにちゃんとTextコンポーネントを設定を設定してもnullエラーが出ます。
ScoreLabelにGameScore.csをアタッチして、ScoreLabelにちゃんとTextコンポーネントを設定を設定してもnullエラーが出ます。
>>次に、GameScoreコンポーネントがつけられているオブジェクトにBall_moveコンポーネントがついてるか見てください。
ここを詳しく説明してもらえないでしょうか。
何卒、よろしくお願います。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/12 06:44
2018/05/12 06:55
2018/05/12 07:00
2018/05/12 07:13