質問編集履歴
1
ソースコードの記載
title
CHANGED
File without changes
|
body
CHANGED
@@ -10,7 +10,192 @@
|
|
10
10
|
### 該当のソースコード
|
11
11
|
|
12
12
|
```C#
|
13
|
+
using System.Collections;
|
14
|
+
using System.Collections.Generic;
|
15
|
+
using UnityEngine;
|
16
|
+
using Photon.Pun;
|
13
17
|
|
18
|
+
public class move_joystick : MonoBehaviourPun
|
19
|
+
{
|
20
|
+
public FixedJoystick joystick;//FixedJoystickを取得
|
21
|
+
|
22
|
+
private float speed = 5.0f;
|
23
|
+
private float jumpPower = 275;
|
24
|
+
private float delay = 0f;
|
25
|
+
public AudioClip MoveSound;
|
26
|
+
public AudioClip JumpSound;
|
27
|
+
private Rigidbody rb;
|
28
|
+
// Start is called before the first frame update
|
29
|
+
void Start()
|
30
|
+
{
|
31
|
+
if (photonView.IsMine)
|
32
|
+
{
|
33
|
+
rb = GetComponent<Rigidbody>();
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
|
38
|
+
// Update is called once per frame
|
39
|
+
void Update()
|
40
|
+
{
|
41
|
+
var x = joystick.Horizontal;
|
42
|
+
var y = joystick.Vertical;
|
43
|
+
float radian = Mathf.Atan2(x, y) * Mathf.Rad2Deg;
|
44
|
+
|
45
|
+
if (radian < 0)
|
46
|
+
{
|
47
|
+
radian += 360;
|
48
|
+
}
|
49
|
+
Debug.Log(radian);
|
50
|
+
|
51
|
+
if(photonView.IsMine)
|
52
|
+
{
|
53
|
+
if (x == 0)
|
54
|
+
{
|
55
|
+
if (y == 0)
|
56
|
+
{
|
57
|
+
return;
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
if (radian <= 15)
|
62
|
+
{
|
63
|
+
|
64
|
+
photonView.RPC(nameof(Move5), RpcTarget.All);
|
65
|
+
Invoke("SoundMove", delay);
|
66
|
+
}
|
67
|
+
|
68
|
+
else if (radian <= 75)
|
69
|
+
{
|
70
|
+
|
71
|
+
photonView.RPC(nameof(Move3), RpcTarget.All);
|
72
|
+
Invoke("SoundMove", delay);
|
73
|
+
}
|
74
|
+
|
75
|
+
else if (radian <= 105)
|
76
|
+
{
|
77
|
+
|
78
|
+
photonView.RPC(nameof(Move1), RpcTarget.All);
|
79
|
+
Invoke("SoundMove", delay);
|
80
|
+
}
|
81
|
+
|
82
|
+
else if (radian <= 165)
|
83
|
+
{
|
84
|
+
|
85
|
+
photonView.RPC(nameof(Move6), RpcTarget.All);
|
86
|
+
Invoke("SoundMove", delay);
|
87
|
+
}
|
88
|
+
|
89
|
+
else if (radian <= 195)
|
90
|
+
{
|
91
|
+
|
92
|
+
photonView.RPC(nameof(Move8), RpcTarget.All);
|
93
|
+
Invoke("SoundMove", delay);
|
94
|
+
}
|
95
|
+
|
96
|
+
else if (radian <= 255)
|
97
|
+
{
|
98
|
+
|
99
|
+
photonView.RPC(nameof(Move7), RpcTarget.All);
|
100
|
+
Invoke("SoundMove", delay);
|
101
|
+
}
|
102
|
+
|
103
|
+
else if (radian <= 285)
|
104
|
+
{
|
105
|
+
|
106
|
+
photonView.RPC(nameof(Move2), RpcTarget.All);
|
107
|
+
Invoke("SoundMove", delay);
|
108
|
+
}
|
109
|
+
|
110
|
+
else if (radian <= 345)
|
111
|
+
{
|
112
|
+
|
113
|
+
photonView.RPC(nameof(Move4), RpcTarget.All);
|
114
|
+
Invoke("SoundMove", delay);
|
115
|
+
}
|
116
|
+
|
117
|
+
else if (radian <= 360)
|
118
|
+
{
|
119
|
+
|
120
|
+
photonView.RPC(nameof(Move5), RpcTarget.All);
|
121
|
+
Invoke("SoundMove", delay);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
Ray ray = new Ray(transform.position, -transform.up);
|
126
|
+
{
|
127
|
+
//接地判定
|
128
|
+
RaycastHit hit;
|
129
|
+
if (Physics.Raycast(ray, out hit, 0.25f))
|
130
|
+
{
|
131
|
+
if (Input.GetKeyDown(KeyCode.O))
|
132
|
+
{
|
133
|
+
rb.AddForce(transform.up * jumpPower);
|
134
|
+
AudioSource.PlayClipAtPoint(JumpSound, transform.position);
|
135
|
+
}
|
136
|
+
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
}
|
141
|
+
void SoundMove()
|
142
|
+
{
|
143
|
+
if (photonView.IsMine)
|
144
|
+
{
|
145
|
+
AudioSource.PlayClipAtPoint(MoveSound, transform.position);
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
[PunRPC]
|
150
|
+
private void Move1()
|
151
|
+
{
|
152
|
+
transform.rotation = Quaternion.AngleAxis(90, new Vector3(0, 1, 0));
|
153
|
+
transform.position += transform.forward * speed * Time.deltaTime;
|
154
|
+
}
|
155
|
+
[PunRPC]
|
156
|
+
private void Move2()
|
157
|
+
{
|
158
|
+
transform.rotation = Quaternion.AngleAxis(-90, new Vector3(0, 1, 0));
|
159
|
+
transform.position += transform.forward * speed * Time.deltaTime;
|
160
|
+
}
|
161
|
+
[PunRPC]
|
162
|
+
private void Move3()
|
163
|
+
{
|
164
|
+
transform.rotation = Quaternion.AngleAxis(45, new Vector3(0, 1, 0));
|
165
|
+
transform.position += transform.forward * speed * Time.deltaTime;
|
166
|
+
}
|
167
|
+
[PunRPC]
|
168
|
+
private void Move4()
|
169
|
+
{
|
170
|
+
transform.rotation = Quaternion.AngleAxis(-45, new Vector3(0, 1, 0));
|
171
|
+
transform.position += transform.forward * speed * Time.deltaTime;
|
172
|
+
}
|
173
|
+
[PunRPC]
|
174
|
+
private void Move5()
|
175
|
+
{
|
176
|
+
transform.rotation = Quaternion.AngleAxis(0, new Vector3(0, 1, 0));
|
177
|
+
transform.position += transform.forward * speed * Time.deltaTime;
|
178
|
+
}
|
179
|
+
[PunRPC]
|
180
|
+
private void Move6()
|
181
|
+
{
|
182
|
+
transform.rotation = Quaternion.AngleAxis(135, new Vector3(0, 1, 0));
|
183
|
+
transform.position += transform.forward * speed * Time.deltaTime;
|
184
|
+
}
|
185
|
+
[PunRPC]
|
186
|
+
private void Move7()
|
187
|
+
{
|
188
|
+
transform.rotation = Quaternion.AngleAxis(-135, new Vector3(0, 1, 0));
|
189
|
+
transform.position += transform.forward * speed * Time.deltaTime;
|
190
|
+
}
|
191
|
+
[PunRPC]
|
192
|
+
private void Move8()
|
193
|
+
{
|
194
|
+
transform.rotation = Quaternion.AngleAxis(180, new Vector3(0, 1, 0));
|
195
|
+
transform.position += transform.forward * speed * Time.deltaTime;
|
196
|
+
}
|
197
|
+
|
198
|
+
}
|
14
199
|
```
|
15
200
|
|
16
201
|
### 試したこと
|