Game Development Reference
In-Depth Information
Finally, we used the
OnDrawGizmos()
funcion to create the visual for the waypoint game
object, which will show only in the editor. We won't see anything while we are playing the
real game after we build it.
However, if we want to see it while we are playing the game in the
Game
view, we can click
on the
Play
buton and click on the
Gizmos
buton on the top-right to toggle the
Gizmos
On
or
Off
as shown in the following screenshot:
Creating an enemy AI
In the last secion, we created the
Waypoints
script and the
Waypoints
object, which will
be used to limit the enemy movement and direcion. In this secion, we need to create the
enemy game object, which will contain the waypoint and our AI character. We will use a
prefab similar to that of the player character but remove some of it that is not necessary for
the enemy.
Engage thrusters
We will start by creaing the empty game object to contain the
AI
and the
Waypoints
object:
1. Go to
GameObject
|
Create Empty
to create the empty game object and name
it
Enemy
. Then, assign its transform by clicking on this game object and go to the
Inspector
view to reset the transform to default, as follows:
Position
X: 0
Y: 0
Z: 0
Rotation
X: 0
Y: 0
Z: 0
Scale
X: 1
Y: 1
Z: 1
2. Next, drag the
Waypoints
game object in the
Hierarchy
view that we created in the
irst secion inside the
Enemy
game object.
3. Then, create another empty game object by going to
GameObject
|
Create Empty
again and this ime name it
AI
. Set the transform in the
AI
game object as follows:
Position
X: 0
Y: 0
Z: 0
Rotation
X: 0
Y: 0
Z: 0
Scale
X: 1
Y: 1
Z: 1