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

回答編集履歴

1

補足

2021/05/19 09:41

投稿

hogefugapiyo
hogefugapiyo

スコア3311

answer CHANGED
@@ -1,4 +1,35 @@
1
1
  該当コードをコピペしてみたんですが特にエラーが確認できず
2
2
  このスクリプト単体がエラー出している感じでしょうか?
3
3
 
4
- MonoBehaviourを継承しない場合、そのスクリプトをGameObjectにアタッチはできません。(アタッチしている場合エラーがでますし、アタッチしようとしてもエラーがます)
4
+ ちなみにMonoBehaviourを継承しない場合、そのスクリプトをGameObjectにアタッチはできません。(アタッチしている場合エラーがでますし、アタッチしようとしてもエラーがます)
5
+
6
+
7
+ たとえば下記構成で、TestをGameObjectにアタッチして実行すると「Hoge」がコンソールに表示されるかとおもいますが、いかがでしょうか。
8
+
9
+ Data.cs
10
+ ```cs
11
+ using System.Collections;
12
+ using System.Collections.Generic;
13
+ using UnityEngine;
14
+
15
+ public class Data {
16
+ public readonly static Data Instance = new Data();
17
+ public string referer = "Hoge";
18
+ }
19
+ ```
20
+
21
+
22
+ Test.cs (GameObjectにアタッチ)
23
+ ```cs
24
+ using System.Collections;
25
+ using System.Collections.Generic;
26
+ using UnityEngine;
27
+
28
+ public class Test : MonoBehaviour {
29
+ // Start is called before the first frame update
30
+ void Start() {
31
+ Debug.Log(Data.Instance.referer);
32
+ }
33
+ }
34
+
35
+ ```