回答編集履歴
1
サンプルソース追記
test
CHANGED
@@ -17,3 +17,113 @@
|
|
17
17
|
Barrett生成時に自機のthis.transform.forwardをBarrettに渡してあげて、このベクトルを利用して進めさせるようにすればいいのではないでしょうか。
|
18
18
|
|
19
19
|
(自機の回転を渡してもできるはずですが、色々ややこしいので向きベクトルでやるのをお勧めします)
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
コードの書き方は勉強していってほしいところですが、とりあえずサンプル載せておきます。
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
```C#
|
28
|
+
|
29
|
+
using System.Collections;
|
30
|
+
|
31
|
+
using System.Collections.Generic;
|
32
|
+
|
33
|
+
using UnityEngine;
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
public class Player : MonoBehaviour {
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
public Barrett barrett;
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
// Use this for initialization
|
46
|
+
|
47
|
+
void Start () {
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
// Update is called once per frame
|
56
|
+
|
57
|
+
void Update () {
|
58
|
+
|
59
|
+
if(Input.GetKey(KeyCode.R))
|
60
|
+
|
61
|
+
{
|
62
|
+
|
63
|
+
this.transform.Rotate(0.0f, 1.0f, 0.0f);
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
if(Input.GetKeyUp(KeyCode.Space))
|
70
|
+
|
71
|
+
{
|
72
|
+
|
73
|
+
Barrett _b = (Barrett)Instantiate(this.barrett, this.transform.position, this.transform.rotation);
|
74
|
+
|
75
|
+
_b.forward = this.transform.forward;
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
```
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
```C#
|
88
|
+
|
89
|
+
using System.Collections;
|
90
|
+
|
91
|
+
using System.Collections.Generic;
|
92
|
+
|
93
|
+
using UnityEngine;
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
public class Barrett : MonoBehaviour {
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
public Vector3 forward;
|
102
|
+
|
103
|
+
public float bulletSpeed = 1.0f;
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
// Use this for initialization
|
108
|
+
|
109
|
+
void Start () {
|
110
|
+
|
111
|
+
var rid = GetComponent<Rigidbody>();
|
112
|
+
|
113
|
+
rid.velocity = this.forward * bulletSpeed;
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
// Update is called once per frame
|
120
|
+
|
121
|
+
void Update () {
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
```
|