Please Help. How do I make the player go to the main menu once they get a certain distance from the enemy?

I have a problem. I have a monster in a game, I have it where he chases me but I want to have a certain distance where the monster can come at me till get sent back to the main menu. How can I do that? I am a beginner so please be simple. Thank you.

In an Update method of some object that can see both the player and monster, you can do something like:

float distance = Vector3.Distance(monster.transform.position, player.transform.position);

to get the distance. And when that’s higher than a number you want, you can put the code to return to menu (I don’t know what you’re using for GUI).

You can use Vector3.Distance to calculate the difference of positions between one object and the other.

For e.g. - Call this function in the update method and it will return d

void checkDistanceOfMonster()
{
	float distance = Vector3.Distance(player.transform.position,monster.transform.position);
	Debug.Log("Distance between player and monster is " + distance);

	if(distance < 10f)
	{
		//Goto main menu
	}
}