質問編集履歴
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -69,3 +69,83 @@
|
|
69
69
|
```
|
70
70
|
|
71
71
|
thisとthis.gameObjectの違いや、使い分けのご教授をお願いします。
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
###追記
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
ゲーム再生時にNullエラーが起きるのを検証しようとしました。
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
まず、ゲームオブジェクトにアタッチしているスクリプトを下記のようにしました。
|
86
|
+
|
87
|
+
```C#
|
88
|
+
|
89
|
+
using UnityEngine;
|
90
|
+
|
91
|
+
using System.Collections;
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
public class Sample: MonoBehaviour{
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
void Start () {
|
100
|
+
|
101
|
+
Hoge hoge = new Hoge ();
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
```
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
次にゲームオブジェクトにアタッチさせないスクリプトも、MonoBehaviourを継承させて、下記のようにしました。
|
112
|
+
|
113
|
+
```C#
|
114
|
+
|
115
|
+
using UnityEngine;
|
116
|
+
|
117
|
+
using System.Collections;
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
public class Hoge: MonoBehaviour{
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
void Start () {
|
126
|
+
|
127
|
+
Debug.Log(this.gameObject);
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
```
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
ゲーム再生時に発生したエラー(警告文)。
|
138
|
+
|
139
|
+
「MonoBehaviourを継承したクラスはnewできない」のでしょうか?
|
140
|
+
|
141
|
+
```
|
142
|
+
|
143
|
+
You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
|
144
|
+
|
145
|
+
UnityEngine.MonoBehaviour:.ctor()
|
146
|
+
|
147
|
+
Hoge:.ctor()
|
148
|
+
|
149
|
+
Sample:Start() (at Assets/Sample.cs:7)
|
150
|
+
|
151
|
+
```
|