How do I get an enemy to flee from the player when shot

I’m trying to make it so that an enemy switches from approaching the player to fleeing from the player when it gets hit, and then go back to chasing the player after a certain amount of time, can anyone help me?

You’ll want to use a pathfinding algorithm like A*. Luckly, Unity’s built-in navigation and pathfinding methods make this easy. To make the enemy chase the player, simply set the enemy’s target waypoint to be the player’s position. Then, to make it flee, pick a random location in the opposite direction of the player (so it’s running away), and set the waypoint there. Then, after that amount of time, simply set the waypoint back to the player.