質問編集履歴
2
おういえす
title
CHANGED
File without changes
|
body
CHANGED
@@ -66,6 +66,76 @@
|
|
66
66
|
}
|
67
67
|
}
|
68
68
|
```
|
69
|
+
敵のAIのコード
|
70
|
+
```C#
|
71
|
+
using System.Collections;
|
72
|
+
using System.Collections.Generic;
|
73
|
+
using UnityEngine;
|
74
|
+
using UnityEngine.AI;
|
75
|
+
|
76
|
+
public class CarAI : MonoBehaviour
|
77
|
+
{
|
78
|
+
[SerializeField, Header("通過点")] private Transform[] passingPoint;
|
79
|
+
private NavMeshAgent nav;
|
80
|
+
private int pointNumber = 0;
|
81
|
+
|
82
|
+
void Start()
|
83
|
+
{
|
84
|
+
nav = GetComponent<NavMeshAgent>();
|
85
|
+
nav.SetDestination(passingPoint[pointNumber].position);
|
86
|
+
}
|
87
|
+
|
88
|
+
private void OnTriggerEnter(Collider other)
|
89
|
+
{
|
90
|
+
// 目的地を設定
|
91
|
+
if (other.gameObject.CompareTag("PassingPoint0"))
|
92
|
+
{
|
93
|
+
pointNumber = 1;
|
94
|
+
nav.SetDestination(passingPoint[pointNumber].position);
|
95
|
+
}
|
96
|
+
else if (other.gameObject.CompareTag("PassingPoint1"))
|
97
|
+
{
|
98
|
+
pointNumber = 2;
|
99
|
+
nav.SetDestination(passingPoint[pointNumber].position);
|
100
|
+
}
|
101
|
+
else if (other.gameObject.CompareTag("PassingPoint2"))
|
102
|
+
{
|
103
|
+
pointNumber = 3;
|
104
|
+
nav.SetDestination(passingPoint[pointNumber].position);
|
105
|
+
}
|
106
|
+
else if (other.gameObject.CompareTag("PassingPoint3"))
|
107
|
+
{
|
108
|
+
pointNumber = 4;
|
109
|
+
nav.SetDestination(passingPoint[pointNumber].position);
|
110
|
+
}
|
111
|
+
else if (other.gameObject.CompareTag("PassingPoint4"))
|
112
|
+
{
|
113
|
+
pointNumber = 5;
|
114
|
+
nav.SetDestination(passingPoint[pointNumber].position);
|
115
|
+
}
|
116
|
+
else if (other.gameObject.CompareTag("PassingPoint5"))
|
117
|
+
{
|
118
|
+
pointNumber = 6;
|
119
|
+
nav.SetDestination(passingPoint[pointNumber].position);
|
120
|
+
}
|
121
|
+
else if (other.gameObject.CompareTag("PassingPoint6"))
|
122
|
+
{
|
123
|
+
pointNumber = 7;
|
124
|
+
nav.SetDestination(passingPoint[pointNumber].position);
|
125
|
+
}
|
126
|
+
else if (other.gameObject.CompareTag("PassingPoint7"))
|
127
|
+
{
|
128
|
+
pointNumber = 8;
|
129
|
+
nav.SetDestination(passingPoint[pointNumber].position);
|
130
|
+
}
|
131
|
+
else if (other.gameObject.CompareTag("PassingPoint8"))
|
132
|
+
{
|
133
|
+
pointNumber = 0;
|
134
|
+
nav.SetDestination(passingPoint[pointNumber].position);
|
135
|
+
}
|
136
|
+
}
|
137
|
+
}
|
138
|
+
```
|
69
139
|
**やった事**
|
70
140
|
参考サイト
|
71
141
|
[NavMeshAgent .Resume](https://translate.google.com/translate?hl=ja&sl=en&u=https://docs.unity3d.com/540/Documentation/ScriptReference/NavMeshAgent.Stop.html&prev=search&pto=aue)
|
1
おういえす
title
CHANGED
File without changes
|
body
CHANGED
@@ -67,6 +67,10 @@
|
|
67
67
|
}
|
68
68
|
```
|
69
69
|
**やった事**
|
70
|
+
参考サイト
|
71
|
+
[NavMeshAgent .Resume](https://translate.google.com/translate?hl=ja&sl=en&u=https://docs.unity3d.com/540/Documentation/ScriptReference/NavMeshAgent.Stop.html&prev=search&pto=aue)
|
72
|
+
[NavMeshAgent .Stop](https://translate.google.com/translate?hl=ja&sl=en&u=https://docs.unity3d.com/540/Documentation/ScriptReference/NavMeshAgent.Stop.html&prev=search&pto=aue)
|
73
|
+
|
70
74
|
そこでアイテムを作成しようとして、調べて実装してみました
|
71
75
|
アイテムに当たったら、スピードをゆっくり落として、一定時間たったら、また再開するというコードを書きました。なのですが、いくつかできておらず、教えてもらいたいです。
|
72
76
|
効率の良いコードの書き方なども教えてもらえたら幸いです。
|