質問編集履歴
1
スクリプトを載せました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,6 +2,46 @@
|
|
2
2
|
現在、Unityで弾幕ゲームを作っています。このように湾曲する敵を作りました。
|
3
3
|

|
4
4
|
|
5
|
+
スクリプトは以下のものです
|
6
|
+
上が左に曲がるという命令、下がまっすぐ進むという命令で、この2つを組み合わせています。
|
7
|
+
```C#
|
8
|
+
using System.Collections;
|
9
|
+
using System.Collections.Generic;
|
10
|
+
using UnityEngine;
|
11
|
+
|
12
|
+
public class Curve : MonoBehaviour
|
13
|
+
{
|
14
|
+
public AnimationCurve curve;
|
15
|
+
|
16
|
+
void Start()
|
17
|
+
{
|
18
|
+
|
19
|
+
}
|
20
|
+
|
21
|
+
void Update()
|
22
|
+
{
|
23
|
+
Rigidbody rb = this.gameObject.GetComponent<Rigidbody>();
|
24
|
+
rb.AddForce(Vector3.left * curve.Evaluate(Time.timeSinceLevelLoad));
|
25
|
+
}
|
26
|
+
```
|
27
|
+
```C#
|
28
|
+
using System.Collections;
|
29
|
+
using System.Collections.Generic;
|
30
|
+
using UnityEngine;
|
31
|
+
|
32
|
+
public class StraightMovement : MonoBehaviour
|
33
|
+
{
|
34
|
+
public float speed;
|
35
|
+
|
36
|
+
void Update()
|
37
|
+
{
|
38
|
+
Rigidbody rb = this.gameObject.GetComponent<Rigidbody>();
|
39
|
+
|
40
|
+
rb.AddForce(transform.forward * speed);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
```
|
44
|
+
|
5
45
|
しかし、コルーチンを使ってこの敵が動き始める時間を1秒遅らせます。
|
6
46
|
すると、このように全然違う動きになってしまいます。
|
7
47
|

|