質問編集履歴
2
情報過不足なため補足させていただきました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -53,3 +53,171 @@
|
|
53
53
|
情報過不足かもしれませんが、アドバイスいただけますと幸いです。
|
54
54
|
|
55
55
|
お手数をお掛けいたしますがどうぞ宜しくお願いいたします。
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
※データと敵キャラのスクリプトをアップさせて頂きました。
|
60
|
+
|
61
|
+
```ここに言語を入力
|
62
|
+
|
63
|
+
using UnityEngine;
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
public class EnemyManager : MonoBehaviour
|
68
|
+
|
69
|
+
{
|
70
|
+
|
71
|
+
[SerializeField] LayerMask blockLayer;
|
72
|
+
|
73
|
+
[SerializeField] GameObject deathEffect;
|
74
|
+
|
75
|
+
public enum DIRECTION_TYPE
|
76
|
+
|
77
|
+
{
|
78
|
+
|
79
|
+
STOP,
|
80
|
+
|
81
|
+
LEFT,
|
82
|
+
|
83
|
+
RIGHT,
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
DIRECTION_TYPE direction = DIRECTION_TYPE.STOP;
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
Rigidbody2D rigidbody2D;
|
92
|
+
|
93
|
+
float speed;
|
94
|
+
|
95
|
+
private void Start()
|
96
|
+
|
97
|
+
{
|
98
|
+
|
99
|
+
rigidbody2D = GetComponent<Rigidbody2D>();
|
100
|
+
|
101
|
+
//右へ
|
102
|
+
|
103
|
+
direction = DIRECTION_TYPE.RIGHT;
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
private void Update()
|
110
|
+
|
111
|
+
{
|
112
|
+
|
113
|
+
if (!IsGround())
|
114
|
+
|
115
|
+
{
|
116
|
+
|
117
|
+
//方向を変える
|
118
|
+
|
119
|
+
ChangeDirection();
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
private void FixedUpdate()
|
132
|
+
|
133
|
+
{
|
134
|
+
|
135
|
+
switch (direction)
|
136
|
+
|
137
|
+
{
|
138
|
+
|
139
|
+
case DIRECTION_TYPE.STOP:
|
140
|
+
|
141
|
+
speed = 0;
|
142
|
+
|
143
|
+
break;
|
144
|
+
|
145
|
+
case DIRECTION_TYPE.RIGHT:
|
146
|
+
|
147
|
+
speed = 3;
|
148
|
+
|
149
|
+
transform.localScale = new Vector3(1, 1, 1);
|
150
|
+
|
151
|
+
break;
|
152
|
+
|
153
|
+
case DIRECTION_TYPE.LEFT:
|
154
|
+
|
155
|
+
speed = -3;
|
156
|
+
|
157
|
+
transform.localScale = new Vector3(-1, 1, 1);
|
158
|
+
|
159
|
+
break;
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
rigidbody2D.velocity = new Vector2(speed, rigidbody2D.velocity.y);
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
bool IsGround()
|
170
|
+
|
171
|
+
{
|
172
|
+
|
173
|
+
Vector3 startVec = transform.position + transform.right * 0.5f * transform.localScale.x;
|
174
|
+
|
175
|
+
Vector3 endVec = startVec - transform.up * 0.5f;
|
176
|
+
|
177
|
+
Debug.DrawLine(startVec, endVec);
|
178
|
+
|
179
|
+
return Physics2D.Linecast(startVec, endVec, blockLayer);
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
void ChangeDirection()
|
184
|
+
|
185
|
+
{
|
186
|
+
|
187
|
+
if(direction== DIRECTION_TYPE.RIGHT)
|
188
|
+
|
189
|
+
{
|
190
|
+
|
191
|
+
direction = DIRECTION_TYPE.LEFT;
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
else if (direction == DIRECTION_TYPE.LEFT)
|
196
|
+
|
197
|
+
{
|
198
|
+
|
199
|
+
direction = DIRECTION_TYPE.RIGHT;
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
public void DestroyEnemy()
|
208
|
+
|
209
|
+
{
|
210
|
+
|
211
|
+
Instantiate(deathEffect, transform.position, transform.rotation);
|
212
|
+
|
213
|
+
Destroy(this.gameObject);
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
```
|
220
|
+
|
221
|
+
・Unityデータ
|
222
|
+
|
223
|
+
https://drive.google.com/file/d/1qjUmVNrzEAIVVDR3o2K6xPWaEpg77QVj/view?usp=sharing
|
1
過不足追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,7 +24,7 @@
|
|
24
24
|
|
25
25
|
■ 解決したい事
|
26
26
|
|
27
|
-
敵キャラが、起動した初回だけ落下してしまう。
|
27
|
+
敵キャラが、ビルドして起動した初回だけ落下してしまう。
|
28
28
|
|
29
29
|
|
30
30
|
|