質問編集履歴

1

追記質問追記

2018/07/08 11:01

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -91,3 +91,95 @@
91
91
  ### 補足情報(FW/ツールのバージョンなど)
92
92
 
93
93
  Unity
94
+
95
+
96
+
97
+ ### 追記質問。
98
+
99
+
100
+
101
+ 「staticメソッド内部に記載された変数はstaticとして扱われる」
102
+
103
+ これをもっと掘り下げると、
104
+
105
+ 「staticメソッド内部に記載されたローカル変数以外の変数やメソッドはstaticとして扱われる。」
106
+
107
+ で合っていますか?
108
+
109
+ また、下記コードのコメントも合っていますか?
110
+
111
+
112
+
113
+ ```C#
114
+
115
+ using System.Collections;
116
+
117
+ using System.Collections.Generic;
118
+
119
+ using UnityEngine;
120
+
121
+
122
+
123
+ public class Sample3 {
124
+
125
+ public int i = 1;
126
+
127
+ static int j = 2;
128
+
129
+
130
+
131
+ public static void staticMethod(){
132
+
133
+ //Debug.Log(i); //Sample3クラスのstaticなiを参照しようとして見つからないのでエラー。
134
+
135
+ Debug.Log(j); //出力:2。Sample3クラスのstaticなjを参照する。
136
+
137
+ MyMethod(); //出力:MyMethod。Sample3クラスのstaticなMyMethodを呼び出す。
138
+
139
+ int k = 3; //staticメソッド内で宣言した変数はローカル変数なのでstaticとして扱われない。
140
+
141
+ Debug.Log(k); //出力:3。
142
+
143
+ Sample3 s = new Sample3(); //staticメソッド内で生成した変数はローカル変数なのでstaticとして扱われない。
144
+
145
+ Debug.Log(s.i); //出力:1。
146
+
147
+ }
148
+
149
+
150
+
151
+ public static void MyMethod(){
152
+
153
+ Debug.Log("MyMethod");
154
+
155
+ }
156
+
157
+
158
+
159
+ }
160
+
161
+ ```
162
+
163
+ ```C#
164
+
165
+ using System.Collections;
166
+
167
+ using System.Collections.Generic;
168
+
169
+ using UnityEngine;
170
+
171
+
172
+
173
+ public class GameManager : MonoBehaviour {
174
+
175
+
176
+
177
+ void Start () {
178
+
179
+ Sample3.staticMethod();
180
+
181
+ }
182
+
183
+ }
184
+
185
+ ```