C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class AIconRoot : MonoBehaviour 6{ 7 // Start is called before the first frame update 8 public List<WayStruct> Waypoint; 9 10 public struct WayStruct 11 { 12 public Vector3 Waypoint; 13 14 public bool Brake; 15 public bool NotAccele; 16 } 17 18 19 20 21 void Start() 22 { 23 24 } 25 26 // Update is called once per frame 27 void Update() 28 { 29 30 } 31 32 void OnDrawGizmos() 33 { 34 for (int n = 0; n < Waypoint.Count; n++) { 35 Gizmos.color = new Color(1f, 0, 0, 1); 36 37 Gizmos.DrawSphere(Waypoint[n].Waypoint, 0.5f); 38 39 40 } 41 for (int n = 0; n < Waypoint.Count; n++) 42 { 43 44 45 46 } 47 for (int n = 1; n < Waypoint.Count; n++) 48 { 49 Gizmos.DrawLine(Waypoint[n-1].Waypoint, Waypoint[n].Waypoint); 50 } 51 } 52} 53
↑のソースコードで。
NullReferenceException: Object reference not set to an instance of an object
AIconRoot.OnDrawGizmos () (at Assets/script/AIconRoot.cs:34)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
↑のエラーが出てしまいました。
google翻訳で翻訳しても意味がわかりませんでした。
何をどのように直せばよいのでしょうか?
どうにかよろしくおねがいします。
コードやエラーはマークダウンのcode機能を利用してご提示ください。
https://teratail.com/questions/238564
>google翻訳で翻訳しても意味がわかりませんでした。
どういう訳が出てきてどう分からなかったのか記載してください。
https://qiita.com/cannorin/items/eb062aae88bfe2ad6fe5
私が試して出てきた訳で何もわからなかったとなると、かなりもっと基本的な部分から学習する必要があると思います。
NullReferenceException: Object reference not set to an instance of an object
AIconRoot.OnDrawGizmos ()
⇓
NullReferenceException:オブジェクト参照がオブジェクトのインスタンスに設定されていません
AIconRoot.OnDrawGizmos()
と出ます
はい。私も同じ内容の翻訳でした。
エラー内容からするとどの変数やオブジェクトに対して起きているかというのも指摘してくれてます。
その時点で、どこがどうわからなかったのかを記載されたほうが良いです。
https://teratail.com/help/question-tips#questionTips2-1
でないと、回答されても理解できない可能性が高く、そうなると結局「もっと基本から」と「質問と回答」という枠におさまらない内容になります。
このスクリプトに対してリストwaypointの要素数を数えるのはWaypoint.Countであってますか?
「参照がnull」という言葉の意味そのものがわからないという話?
だったらまずC#の入門書を買って頭から半分ぐらいはしっかり読み直したほうが良い。
>リストwaypointの要素数を数えるのは
の前に、変数参照する直前でデバッグして変数に何が入ってるか確認してください。
うーん参照がnullってことはアクセスできないとかそもそもその値がないとかであってますかね?
あ、値を割りふっていませんでしたご迷惑をおかけしてしい申し訳ございません。
回答1件
あなたの回答
tips
プレビュー