質問編集履歴

2

コード追記

2018/01/25 15:35

投稿

japomondo
japomondo

スコア23

test CHANGED
File without changes
test CHANGED
@@ -119,3 +119,85 @@
119
119
  [https://docs.unity3d.com/jp/540/ScriptReference/Physics.BoxCast.html](https://docs.unity3d.com/jp/540/ScriptReference/Physics.BoxCast.html)
120
120
 
121
121
  [http://tsubakit1.hateblo.jp/entry/2016/02/25/025922](http://tsubakit1.hateblo.jp/entry/2016/02/25/025922)
122
+
123
+
124
+
125
+ ### 追記(コードのみ記載)
126
+
127
+ ```C#
128
+
129
+ using UnityEngine;
130
+
131
+ using System.Collections;
132
+
133
+ using UniRx;
134
+
135
+ using UniRx.Triggers;
136
+
137
+
138
+
139
+ public class Boxcast : MonoBehaviour
140
+
141
+ {
142
+
143
+ Transform myTransform;
144
+
145
+
146
+
147
+ RaycastHit hit;
148
+
149
+
150
+
151
+ // Rayボックスの各軸の半分のサイズ
152
+
153
+ public Vector3 rayRange = new Vector3(5, 0.05f, 0.05f);
154
+
155
+
156
+
157
+ // Rayの最大距離
158
+
159
+ public float rayLength = 15;
160
+
161
+
162
+
163
+ GameObject player;
164
+
165
+
166
+
167
+ void Start ()
168
+
169
+ {
170
+
171
+ myTransform = transform;
172
+
173
+
174
+
175
+ player = GameObject.FindWithTag("Player");
176
+
177
+
178
+
179
+   // コライダがヒットした場合、追跡モードに切り替え
180
+
181
+ this.UpdateAsObservable()
182
+
183
+ .Where(_ => Physics.BoxCast (myTransform.position, rayRange, myTransform.forward, out hit, myTransform.rotation, rayLength) && hit.collider.tag == "Player")
184
+
185
+ .Subscribe(_ => Ray());
186
+
187
+ }
188
+
189
+
190
+
191
+ void Ray ()
192
+
193
+ {
194
+
195
+ // 追跡を開始するコードを記載
196
+
197
+ }
198
+
199
+ }
200
+
201
+
202
+
203
+ ```

1

文言修正

2018/01/25 15:35

投稿

japomondo
japomondo

スコア23

test CHANGED
File without changes
test CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
 
12
12
 
13
- NPCは、通常時は決まったルートを巡回しており、自身の子オブジェクトから発するRayがプレイヤーのコライダにヒットした場合、追跡モードに切り替る、という仕様を実現したいと考えています。
13
+ 通常時は決まったルートを巡回しているNPCが、自身の子オブジェクトから発するRayがプレイヤーのコライダにヒットした場合、追跡モードに切り替る、という仕様を考えています。
14
14
 
15
15
 
16
16