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:
- 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.
- Set Up Animation Controller:
- Create an animation controller for the gargoyle.
- Assign relevant animations (like idle) to the controller.
- Add Capsule Collider:
- Attach a capsule collider to the gargoyle prefab.
- Adjust the size and position of the collider to fit the model.
- 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.
- 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.
- Place Gargoyle in Scene:
- Position the gargoyle prefab in the scene where it can observe the player.
- Test the Setup:
- Run the game and test the gargoyle’s ability to detect and react to the player.