Back to Browse

Enemy Follow in Unity 2D - Tutorial for Beginners

465 views
Oct 27, 2025
9:25

In this video, you will learn how to make a 2D enemy object that will follow your player. No plugin needed, just Unity and C#. The first thing you need to do is to load a sprite sheet that will be used as an enemy. There are three enemies in this project, so pay attention to the sprites. You can download the sprite sheet here: https://drive.google.com/file/d/1KKLiLRmv3rbyw8mnLzJkBAZT0JbwAOok/view?usp=sharing In order to make enemies follow the player in Unity, these two components are important: public float speed and public transform player. In void Start(), it is important to tell the script to find game object with tag player, and the reference to the player's transform component. In void Update(), check if the player isn't null to avoid Null Reference exception errors. Inside the if statement, these two lines are important: Vector2 direction, which normalizes the player position with the enemy's transform position, and the second line which tells transform.position = Vector2.MoveTowards(), it consists of three components: transform.position, player.position and speed, multiplied with Time.deltaTime. These three components move the enemy towards player and multiply the movement with speed value. This tutorial also contains a script that is used for randomly spawning the enemies. To do that, make the prefabs and add a GameObject array that will instantiate the enemies in a coroutine. The coroutine will have a while-loop that will spawn the enemies on random position by random order. Support the Creator of Kozmobot on the social networks! CHECK OUT MY WEBSITE: http://kozmobot.com INSTAGRAM: https://www.instagram.com/kozmobot.channel TIKTOK: https://www.tiktok.com/@kozmobot.channel

Download

0 formats

No download links available.

Enemy Follow in Unity 2D - Tutorial for Beginners | NatokHD