質問編集履歴
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
Staticな床オブジェクトに、移動するNavMesh Agentがついたオブジェクト(agent.gameObject)があります。
|
2
2
|
すでにNavigationはBakeされています。
|
3
3
|
|
4
|
+
下記のコードは「**Move()**を実行するとこのオブジェクトはx,z軸ランダムに最大20m移動する」というものです。
|
4
5
|
```C#
|
5
6
|
NavMeshAgent agent;
|
6
7
|
|
7
8
|
void Move(){
|
8
|
-
Vector3 position = new Vector3(gameObject.transform.position.x + Random.Range(
|
9
|
+
Vector3 position = new Vector3(gameObject.transform.position.x + Random.Range(-20, 20), 0.2f, gameObject.transform.position.z + Random.Range(-20, 20));
|
9
10
|
|
10
11
|
NavMeshHit Hit;
|
11
12
|
if (NavMesh.SamplePosition(position,out Hit, 1.0f, NavMesh.AllAreas))
|