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

質問編集履歴

3

修正

2021/10/10 03:28

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -48,28 +48,4 @@
48
48
  また、ItemクラスにMonoBehaviourを継承させると、Itemクラスのフィールドがインスペクタで表示されなくなってしまいました。
49
49
  Serializable属性は、MonoBehaviourを継承しないクラスに付与させる属性ということでしょうか?
50
50
  そうすると、このItemクラスのフィールドを表示させるには、
51
- 他のMonoBehaviour継承クラスのSerializeFieldでこのItemクラス自体も参照させなければならなくなるということでしょうか?
51
+ 他のMonoBehaviour継承クラスのSerializeFieldでこのItemクラス自体も参照させなければならなくなるということでしょうか?
52
-
53
- ### 追記質問
54
- 「item.type == item.Type.Cube」のような比較をしたいのですが、エラーとなってしまいます。
55
- どういった修正をすればよいでしょうか?
56
- ```C#
57
- using System.Collections;
58
- using System.Collections.Generic;
59
- using UnityEngine;
60
-
61
- public class PickupObj : MonoBehaviour
62
- {
63
- [SerializeField] Item item;
64
-
65
- void Start(){
66
- Debug.Log(item.type);
67
- Debug.Log(item.type == item.Type.Cube); // エラー
68
- Debug.Log(item.sprite);
69
- }
70
- }
71
- ```
72
-
73
- ```
74
- 'Type': cannot reference a type through an expression; try 'Item.Type' instead
75
- ```

2

エラーメッセージ追記

2021/10/10 03:28

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -68,4 +68,8 @@
68
68
  Debug.Log(item.sprite);
69
69
  }
70
70
  }
71
+ ```
72
+
73
+ ```
74
+ 'Type': cannot reference a type through an expression; try 'Item.Type' instead
71
75
  ```

1

質問追記

2021/10/09 07:28

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -48,4 +48,24 @@
48
48
  また、ItemクラスにMonoBehaviourを継承させると、Itemクラスのフィールドがインスペクタで表示されなくなってしまいました。
49
49
  Serializable属性は、MonoBehaviourを継承しないクラスに付与させる属性ということでしょうか?
50
50
  そうすると、このItemクラスのフィールドを表示させるには、
51
- 他のMonoBehaviour継承クラスのSerializeFieldでこのItemクラス自体も参照させなければならなくなるということでしょうか?
51
+ 他のMonoBehaviour継承クラスのSerializeFieldでこのItemクラス自体も参照させなければならなくなるということでしょうか?
52
+
53
+ ### 追記質問
54
+ 「item.type == item.Type.Cube」のような比較をしたいのですが、エラーとなってしまいます。
55
+ どういった修正をすればよいでしょうか?
56
+ ```C#
57
+ using System.Collections;
58
+ using System.Collections.Generic;
59
+ using UnityEngine;
60
+
61
+ public class PickupObj : MonoBehaviour
62
+ {
63
+ [SerializeField] Item item;
64
+
65
+ void Start(){
66
+ Debug.Log(item.type);
67
+ Debug.Log(item.type == item.Type.Cube); // エラー
68
+ Debug.Log(item.sprite);
69
+ }
70
+ }
71
+ ```