質問編集履歴
1
スクリプトの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
メソッドは呼び出されますが、代入ができません。原因は何でしょうか。
|
4
4
|
|
5
|
+
|
6
|
+
|
7
|
+
呼び出される側
|
8
|
+
|
5
9
|
```C#
|
6
10
|
|
7
11
|
using System.Collections;
|
@@ -79,3 +83,139 @@
|
|
79
83
|
|
80
84
|
|
81
85
|
```
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
get〇〇〇を呼び出す側
|
90
|
+
|
91
|
+
```c#
|
92
|
+
|
93
|
+
using UnityEngine;
|
94
|
+
|
95
|
+
using System.Collections;
|
96
|
+
|
97
|
+
using System.Collections.Generic;
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
public class TestTarget : MonoBehaviour {
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
public Texture2D cursor; // カーソルに使用するテクスチャ
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
public AudioClip shot;
|
114
|
+
|
115
|
+
private AudioSource audioSource;
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
GameObject director;
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
void Start () {
|
126
|
+
|
127
|
+
// カーソルを自前のカーソルに変更
|
128
|
+
|
129
|
+
Cursor.SetCursor (cursor, new Vector2 (cursor.width / 2, cursor.height / 2), CursorMode.ForceSoftware);
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
audioSource = gameObject.GetComponent<AudioSource> ();
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
this.director = GameObject.Find ("GameDirector");
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
void Update () {
|
144
|
+
|
145
|
+
// マウスの左クリックで撃つ
|
146
|
+
|
147
|
+
if(Input.GetButtonDown("Fire1")) {
|
148
|
+
|
149
|
+
Shot();
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
if (Input.GetMouseButtonDown (0)) {
|
154
|
+
|
155
|
+
audioSource.PlayOneShot (shot);
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
// 敵を撃つ
|
172
|
+
|
173
|
+
void Shot() {
|
174
|
+
|
175
|
+
Ray ray2 = Camera.main.ScreenPointToRay(Input.mousePosition);
|
176
|
+
|
177
|
+
RaycastHit hit2;
|
178
|
+
|
179
|
+
if(Physics.Raycast(ray2, out hit2, 100f, LayerMask.GetMask("Enemy"))) {
|
180
|
+
|
181
|
+
if (Physics.Raycast(ray2,out hit2)){
|
182
|
+
|
183
|
+
if (hit2.collider.tag == "100"){
|
184
|
+
|
185
|
+
this.director.GetComponent<GameDirector>().get100();
|
186
|
+
|
187
|
+
Debug.Log ("+100");
|
188
|
+
|
189
|
+
}else if(hit2.collider.tag == "500"){
|
190
|
+
|
191
|
+
this.director.GetComponent<GameDirector>().get500();
|
192
|
+
|
193
|
+
Debug.Log ("+500");
|
194
|
+
|
195
|
+
}else if(hit2.collider.tag == "1000"){
|
196
|
+
|
197
|
+
this.director.GetComponent<GameDirector>().get1000();
|
198
|
+
|
199
|
+
Debug.Log ("+1000");
|
200
|
+
|
201
|
+
}else if(hit2.collider.tag == "5000"){
|
202
|
+
|
203
|
+
this.director.GetComponent<GameDirector>().get5000();
|
204
|
+
|
205
|
+
Debug.Log ("+5000");
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
Destroy(hit2.collider.gameObject);
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
```
|