Curriculum
Course: How to develop 3D Games with Unity
Login
Video lesson

Enemies – Part 1 – Static Observers – Part 1

Summary

You’ve now spent a long time developing your game, improving your understanding of scripting in C# along the way. But something’s missing: what’s a stealth game without enemies to evade?

In this tutorial, you’ll:

  • Create a static Gargoyle enemy
  • Write a custom script so the Gargoyle can find JohnLemon
  • Set the game to restart if JohnLemon is caught
  • Once you’ve completed this tutorial, you’ll have one type of enemy ready for your level.

Steps:

  1. Create Gargoyle Prefab:
    • Locate the gargoyle model in the Unity project.
    • Drag the gargoyle model into the scene to create an instance.
    • Convert the model instance to a prefab for further modifications.
  2. Set Up Animation Controller:
    • Create an animation controller for the gargoyle.
    • Assign relevant animations (like idle) to the controller.
  3. Add Capsule Collider:
    • Attach a capsule collider to the gargoyle prefab.
    • Adjust the size and position of the collider to fit the model.
  4. Implement Line of Sight:
    • Add an empty GameObject to represent the gargoyle’s line of sight.
    • Configure its position and orientation to mimic the gargoyle’s view.
    • Add a capsule collider set to trigger mode to detect the player.
  5. Scripting Enemy Behavior:
    • Write and attach a script to control the gargoyle’s behavior.
    • The script should include logic for detecting the player and triggering game over.
  6. Place Gargoyle in Scene:
    • Position the gargoyle prefab in the scene where it can observe the player.
  7. Test the Setup:
    • Run the game and test the gargoyle’s ability to detect and react to the player.