How to make enemy teleport right next to player?

I am making a horror game and was wondering how to make an enemy appear (teleport) right next to the player, to scare them. There is only one enemy in the house, so i need the enemy to teleport instead of just spawning next to the player. Any ideas on how to do this?

function Update () {
transform.position = Vector3(X, Y, Z); //change x, y, z to where you want
yieldWaitForSeconds(2);
transform.position = Vector3(X, Y, Z); //change x, y, z to somewhere where it’s not visible for your controller.
}
}

I’m not sure if this works. I just wrote it down. But try it. If not, I will give you another way.

function Update ()
{
 transform.position = Vector3(X, Y, Z); //change x, y, z to where you want
}

public Transform ScaryMonster;
public Transform ScaredPlayer;
public int FirstAppear = 0;

	private int MonsterStayTime = 1;
	public int Random1;
	public int Random2;
	private Random RandomTime;
	
	void Update ()
	{
		RandomTime = Random.Range(Random1, Random2);
		FirstAppear += Time.time;
		
		if (FirstAppear = 20)
		{
			Transform scarymonster;
			scarymonster = Instantiate (ScaryMonster, ScaredPlayer.position, scarymonster.LookAt(ScaredPlayer)) as Transform;
			Destroy (ScaryMonster, MonsterStayTime);
			Random1 = 30;
			Random2 = 40;
		}
		if (RandomTime <= Time.time)
		{
			scarymonster = Instantiate (ScaryMonster, ScaredPlayer.position, scarymonster.LookAt(ScaredPlayer)) as Transform;
			Destroy (ScaryMonster, MonsterStayTime);
			Random1 = 80;
			Random2 = 90;
		}
		if (RandomTime <= Time.time)
		{
			scarymonster = Instantiate (ScaryMonster, ScaredPlayer.position, scarymonster.LookAt(ScaredPlayer)) as Transform;
			Destroy (ScaryMonster, MonsterStayTime);
			Random1 = 120;
			Random2 = 130;
		}
		/* you get the drift, you just have to copy the above code multiple times for how ever many times you want */
	}

You could attach this to your enemy:

var Player : Transform;
function Start(){
Teleport();
}
function Teleport(){
yield WaitForSeconds(10);
transform.position = Vector3(Player.position.x - 5, Player.position.y - 5, Player.position.y);
yield WaitForSeconds(0.5);
renderer.enabled = false
}

This will wait for 10 secs, then teleport behind the player for 0.5 secs, then hide.
To make the enemy teleport in front of the player, change “- 5” to “+ 5”