Game Development Reference
In-Depth Information
Make it move
For the purpose of this game, we're going to have the enemies walk back and forth
on the platforms. The concept we're going to use here is that of a main object with
two notification objects. The notification objects sit on either side of the
Enemy
object
and simply tell it when it is about to walk off of a platform object. The notification
objects do this by acting as
triggers
and checking to see when they have left the
collision area of the
Platform
object:
1.
Create two empty GameObjects. Name them
LeftGuide
and
RightGuide
respectively, and then make these children of the
Enemy
object.
2.
Give each one a Box Collider 2D component, check the
Is Trigger
boxes
on both, and set their
Size
property as
X: 0.48
,
Y: 0.64
.
3.
Arrange them so that they are on either side of the enemy, outside of its main
Box Collider 2D, and just off to the sides of the visual sprite. The following
screenshot shows how that looks:
4.
Now, create a new script called
EnemyGuideWatcher
and code it up
as follows:
using UnityEngine;
using System.Collections;
public class EnemyGuideWatcher : MonoBehaviour
{