前提・実現したいこと
簡単な2DゲームをUnity5を使用して作成しています。
Object.CarとObject.flagのx座標の差を求め、flagまでの距離を表示するUIを作成しています。
発生している問題・エラーメッセージ
NullReferenceException: Object reference not set to an instance of an object GameDirector.Update () (at Assets/GameDirector.cs:19)
Assets/GameDirector.cs(24,246): error CS1525: Unexpected symbol `end-of-file'
該当のソースコード
using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class GameDirector : MonoBehaviour { GameObject car; GameObject flag; GameObject distance; void Start () { this.car = GameObject.Find("Car"); this.flag = GameObject.Find("flag"); this.distance = GameObject.Find("distance"); } void Update () { float length = this.flag.transform.position.x - this.car.transform.position.x; if (length >= 0) { this.distance.GetComponent<Text> ().text = "ゴールまで" + length.ToString ("F2") + "m"; } else { this.distance.GetComponent<Text> ().text = "game over"; } }
補足情報
使用しているのはUnity5で使用言語はC#です。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。