teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

現状況を追記した

2019/03/12 15:32

投稿

pokapoka2804
pokapoka2804

スコア15

title CHANGED
File without changes
body CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  ### 該当のソースコード
16
16
 
17
- ```ここに言語名を入力
17
+ ```C#
18
18
  using System.Collections;
19
19
  using System.Collections.Generic;
20
20
  using UnityEngine;
@@ -81,11 +81,13 @@
81
81
  ```
82
82
 
83
83
  ### 試したこと
84
-
85
84
  あるブログを参考にしていて、メッセージ(質問)を送ろうとしたら送信できませんでした。
86
85
  (その後、色々調べて試行錯誤したが他のエラーが出てしまう)
87
- 上記のエラーを読んでも何をどうすればいいのかがまだはっきりわかりません
88
86
 
87
+ 追記
88
+ 17行目 CreateSlot (itemDataBase.GetItemData ());
89
+ からCreateSlot関数にデータを渡す?時に問題があるようです
90
+ (Awake()やOnEnable()はDebug.Log()を使うとコンソールに表示されるので)
89
91
  ### 補足情報(FW/ツールのバージョンなど)
90
92
  unity 2018.3.3f1
91
93
  よろしくおねがいします

2

ソースコードの不足

2019/03/12 15:32

投稿

pokapoka2804
pokapoka2804

スコア15

title CHANGED
File without changes
body CHANGED
@@ -55,6 +55,29 @@
55
55
  }
56
56
  }
57
57
 
58
+
59
+ using System.Collections;
60
+ using System.Collections.Generic;
61
+ using UnityEngine;
62
+
63
+ public class ItemDataBase : MonoBehaviour
64
+ {
65
+ ItemData[] itemlists = new ItemData[2];
66
+
67
+ // Start is called before the first frame update
68
+ void Awake()
69
+ {
70
+ itemlists [0] = new ItemData (Resources.Load ("prefab name", typeof(Sprite))as Sprite, "namae",MyItem.Item.FlashLight, "info");
71
+ itemlists [1] = new ItemData (Resources.Load ("prefab name2", typeof(Sprite))as Sprite, "nam",MyItem.Item.FlashLight, "info");
72
+
73
+ }
74
+ public ItemData[] GetItemData() {
75
+ return itemlists;
76
+ }
77
+ public int GetItemTotal() {
78
+ return itemlists.Length;
79
+ }
80
+ }
58
81
  ```
59
82
 
60
83
  ### 試したこと

1

ソースコードの行数がわかりづらかった

2019/03/06 15:15

投稿

pokapoka2804
pokapoka2804

スコア15

title CHANGED
File without changes
body CHANGED
@@ -7,6 +7,9 @@
7
7
  Google翻訳
8
8
  NullReferenceException:オブジェクト参照がオブジェクトのインスタンスに設定されていません
9
9
 
10
+ 17行目
11
+ CreateSlot (itemDataBase.GetItemData ());
12
+
10
13
  ```
11
14
 
12
15
  ### 該当のソースコード
@@ -28,7 +31,7 @@
28
31
  private ItemDataBase itemDataBase;
29
32
  void OnEnable() {
30
33
  // アイテムデータベースに登録されているアイテム用のスロットを全作成
31
- CreateSlot (itemDataBase.GetItemData ());
34
+ 17行目 CreateSlot (itemDataBase.GetItemData ());
32
35
  }
33
36
  // アイテムスロットの作成
34
37
  public void CreateSlot(ItemData[] itemList) {