質問編集履歴

1

ソースコードの記載

2020/11/25 17:53

投稿

Jejeje
Jejeje

スコア38

test CHANGED
File without changes
test CHANGED
@@ -22,7 +22,377 @@
22
22
 
23
23
  ```C#
24
24
 
25
-
25
+ using System.Collections;
26
+
27
+ using System.Collections.Generic;
28
+
29
+ using UnityEngine;
30
+
31
+ using Photon.Pun;
32
+
33
+
34
+
35
+ public class move_joystick : MonoBehaviourPun
36
+
37
+ {
38
+
39
+ public FixedJoystick joystick;//FixedJoystickを取得
40
+
41
+
42
+
43
+ private float speed = 5.0f;
44
+
45
+ private float jumpPower = 275;
46
+
47
+ private float delay = 0f;
48
+
49
+ public AudioClip MoveSound;
50
+
51
+ public AudioClip JumpSound;
52
+
53
+ private Rigidbody rb;
54
+
55
+ // Start is called before the first frame update
56
+
57
+ void Start()
58
+
59
+ {
60
+
61
+ if (photonView.IsMine)
62
+
63
+ {
64
+
65
+ rb = GetComponent<Rigidbody>();
66
+
67
+ }
68
+
69
+ }
70
+
71
+
72
+
73
+
74
+
75
+ // Update is called once per frame
76
+
77
+ void Update()
78
+
79
+ {
80
+
81
+ var x = joystick.Horizontal;
82
+
83
+ var y = joystick.Vertical;
84
+
85
+ float radian = Mathf.Atan2(x, y) * Mathf.Rad2Deg;
86
+
87
+
88
+
89
+ if (radian < 0)
90
+
91
+ {
92
+
93
+ radian += 360;
94
+
95
+ }
96
+
97
+ Debug.Log(radian);
98
+
99
+
100
+
101
+ if(photonView.IsMine)
102
+
103
+ {
104
+
105
+ if (x == 0)
106
+
107
+ {
108
+
109
+ if (y == 0)
110
+
111
+ {
112
+
113
+ return;
114
+
115
+ }
116
+
117
+ }
118
+
119
+
120
+
121
+ if (radian <= 15)
122
+
123
+ {
124
+
125
+
126
+
127
+ photonView.RPC(nameof(Move5), RpcTarget.All);
128
+
129
+ Invoke("SoundMove", delay);
130
+
131
+ }
132
+
133
+
134
+
135
+ else if (radian <= 75)
136
+
137
+ {
138
+
139
+
140
+
141
+ photonView.RPC(nameof(Move3), RpcTarget.All);
142
+
143
+ Invoke("SoundMove", delay);
144
+
145
+ }
146
+
147
+
148
+
149
+ else if (radian <= 105)
150
+
151
+ {
152
+
153
+
154
+
155
+ photonView.RPC(nameof(Move1), RpcTarget.All);
156
+
157
+ Invoke("SoundMove", delay);
158
+
159
+ }
160
+
161
+
162
+
163
+ else if (radian <= 165)
164
+
165
+ {
166
+
167
+
168
+
169
+ photonView.RPC(nameof(Move6), RpcTarget.All);
170
+
171
+ Invoke("SoundMove", delay);
172
+
173
+ }
174
+
175
+
176
+
177
+ else if (radian <= 195)
178
+
179
+ {
180
+
181
+
182
+
183
+ photonView.RPC(nameof(Move8), RpcTarget.All);
184
+
185
+ Invoke("SoundMove", delay);
186
+
187
+ }
188
+
189
+
190
+
191
+ else if (radian <= 255)
192
+
193
+ {
194
+
195
+
196
+
197
+ photonView.RPC(nameof(Move7), RpcTarget.All);
198
+
199
+ Invoke("SoundMove", delay);
200
+
201
+ }
202
+
203
+
204
+
205
+ else if (radian <= 285)
206
+
207
+ {
208
+
209
+
210
+
211
+ photonView.RPC(nameof(Move2), RpcTarget.All);
212
+
213
+ Invoke("SoundMove", delay);
214
+
215
+ }
216
+
217
+
218
+
219
+ else if (radian <= 345)
220
+
221
+ {
222
+
223
+
224
+
225
+ photonView.RPC(nameof(Move4), RpcTarget.All);
226
+
227
+ Invoke("SoundMove", delay);
228
+
229
+ }
230
+
231
+
232
+
233
+ else if (radian <= 360)
234
+
235
+ {
236
+
237
+
238
+
239
+ photonView.RPC(nameof(Move5), RpcTarget.All);
240
+
241
+ Invoke("SoundMove", delay);
242
+
243
+ }
244
+
245
+ }
246
+
247
+
248
+
249
+ Ray ray = new Ray(transform.position, -transform.up);
250
+
251
+ {
252
+
253
+ //接地判定
254
+
255
+ RaycastHit hit;
256
+
257
+ if (Physics.Raycast(ray, out hit, 0.25f))
258
+
259
+ {
260
+
261
+ if (Input.GetKeyDown(KeyCode.O))
262
+
263
+ {
264
+
265
+ rb.AddForce(transform.up * jumpPower);
266
+
267
+ AudioSource.PlayClipAtPoint(JumpSound, transform.position);
268
+
269
+ }
270
+
271
+
272
+
273
+ }
274
+
275
+ }
276
+
277
+
278
+
279
+ }
280
+
281
+ void SoundMove()
282
+
283
+ {
284
+
285
+ if (photonView.IsMine)
286
+
287
+ {
288
+
289
+ AudioSource.PlayClipAtPoint(MoveSound, transform.position);
290
+
291
+ }
292
+
293
+ }
294
+
295
+
296
+
297
+ [PunRPC]
298
+
299
+ private void Move1()
300
+
301
+ {
302
+
303
+ transform.rotation = Quaternion.AngleAxis(90, new Vector3(0, 1, 0));
304
+
305
+ transform.position += transform.forward * speed * Time.deltaTime;
306
+
307
+ }
308
+
309
+ [PunRPC]
310
+
311
+ private void Move2()
312
+
313
+ {
314
+
315
+ transform.rotation = Quaternion.AngleAxis(-90, new Vector3(0, 1, 0));
316
+
317
+ transform.position += transform.forward * speed * Time.deltaTime;
318
+
319
+ }
320
+
321
+ [PunRPC]
322
+
323
+ private void Move3()
324
+
325
+ {
326
+
327
+ transform.rotation = Quaternion.AngleAxis(45, new Vector3(0, 1, 0));
328
+
329
+ transform.position += transform.forward * speed * Time.deltaTime;
330
+
331
+ }
332
+
333
+ [PunRPC]
334
+
335
+ private void Move4()
336
+
337
+ {
338
+
339
+ transform.rotation = Quaternion.AngleAxis(-45, new Vector3(0, 1, 0));
340
+
341
+ transform.position += transform.forward * speed * Time.deltaTime;
342
+
343
+ }
344
+
345
+ [PunRPC]
346
+
347
+ private void Move5()
348
+
349
+ {
350
+
351
+ transform.rotation = Quaternion.AngleAxis(0, new Vector3(0, 1, 0));
352
+
353
+ transform.position += transform.forward * speed * Time.deltaTime;
354
+
355
+ }
356
+
357
+ [PunRPC]
358
+
359
+ private void Move6()
360
+
361
+ {
362
+
363
+ transform.rotation = Quaternion.AngleAxis(135, new Vector3(0, 1, 0));
364
+
365
+ transform.position += transform.forward * speed * Time.deltaTime;
366
+
367
+ }
368
+
369
+ [PunRPC]
370
+
371
+ private void Move7()
372
+
373
+ {
374
+
375
+ transform.rotation = Quaternion.AngleAxis(-135, new Vector3(0, 1, 0));
376
+
377
+ transform.position += transform.forward * speed * Time.deltaTime;
378
+
379
+ }
380
+
381
+ [PunRPC]
382
+
383
+ private void Move8()
384
+
385
+ {
386
+
387
+ transform.rotation = Quaternion.AngleAxis(180, new Vector3(0, 1, 0));
388
+
389
+ transform.position += transform.forward * speed * Time.deltaTime;
390
+
391
+ }
392
+
393
+
394
+
395
+ }
26
396
 
27
397
  ```
28
398