質問編集履歴
2
詳細追記しました、よろしくお願いします
test
CHANGED
File without changes
|
test
CHANGED
@@ -48,7 +48,7 @@
|
|
48
48
|
|
49
49
|
というスプリクトを当てて移動するようにし、プレハブ化したボールのオブジェクトを
|
50
50
|
|
51
|
-
![
|
51
|
+
![イメージ説明](e3c9bef0dca794db06fb78df4d77e3ed.png)
|
52
52
|
|
53
53
|
この大砲のオブジェクトに
|
54
54
|
|
1
詳細追記しました、よろしくお願いします
test
CHANGED
File without changes
|
test
CHANGED
@@ -3,3 +3,101 @@
|
|
3
3
|
別スプリクトでプレハブ化したボールのx,z座標を取得し、それを跳ね返すように敵のオブジェクトを左右に移動させるC#スプリクトを書きたいです。
|
4
4
|
|
5
5
|
宜しくお願いします。
|
6
|
+
|
7
|
+
追記
|
8
|
+
|
9
|
+
Rigidbodyでy方向の移動と回転をフリーズ、Use Gravityのチェックを外して、
|
10
|
+
|
11
|
+
```c#
|
12
|
+
|
13
|
+
using UnityEngine;
|
14
|
+
|
15
|
+
using System.Collections;
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
public class ballmove : MonoBehaviour {
|
20
|
+
|
21
|
+
public int speed;
|
22
|
+
|
23
|
+
Rigidbody rb;
|
24
|
+
|
25
|
+
// Use this for initialization
|
26
|
+
|
27
|
+
void Start () {
|
28
|
+
|
29
|
+
rb = GetComponent<Rigidbody>();
|
30
|
+
|
31
|
+
rb.AddForce((transform.up + transform.right) * speed, ForceMode.VelocityChange);
|
32
|
+
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
// Update is called once per frame
|
38
|
+
|
39
|
+
void Update () {
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
というスプリクトを当てて移動するようにし、プレハブ化したボールのオブジェクトを
|
50
|
+
|
51
|
+
![全体図](e5f680a4424f96b914a08b6736b375d2.png)
|
52
|
+
|
53
|
+
この大砲のオブジェクトに
|
54
|
+
|
55
|
+
```C#
|
56
|
+
|
57
|
+
using UnityEngine;
|
58
|
+
|
59
|
+
using System.Collections;
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
public class shoot1 : MonoBehaviour {
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
// Use this for initialization
|
68
|
+
|
69
|
+
void Start () {
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
public GameObject ball;
|
76
|
+
|
77
|
+
// Update is called once per frame
|
78
|
+
|
79
|
+
void Update () {
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
if(Input.GetButtonDown("ball1")){
|
84
|
+
|
85
|
+
Instantiate(ball,transform.position,transform.rotation);
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
```
|
96
|
+
|
97
|
+
というスプリクトをあててボールを発射させるようにしました。
|
98
|
+
|
99
|
+
図の上にある黒いバーが敵で、上記で発射されたボールのx,z座標を取得し、if文でボールのz軸が0より大きくなったら得たx軸座標へ決めた一定のスピードで移動して、間に合えばボールを跳ね返す
|
100
|
+
|
101
|
+
よう動作するc#スクリプトを書きたいです。
|
102
|
+
|
103
|
+
よろしくお願いします。
|