# Help needed for a slender script.

So I am trying to create this slender game and I need it done soon. I have the following code so far. (Btw, I’m a beginner):

``````var target : Transform; //the enemy's target
var moveSpeed = 3; //move speed
var rotationSpeed = 3; //speed of turning
var range : float=10f;
var range2 : float=10f;
var stop : float=0;
var myTransform : Transform; //CURRENT TRANSFORM data of this enemy
function Awake()
{
myTransform = transform; //cache transform data for easy access/preformance
}

function Start()
{
target = GameObject.FindWithTag("Player").transform; //target the player

}

function Update () {
//rotate to look at the player
var distance = Vector3.Distance(myTransform.position, target.position);
if (distance<=range2 &&  distance>=range){
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
}

else if(distance<=range && distance>stop){

//move towards the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
else if (distance<=stop) {
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
}

}
``````

So what this code does is making something follow you. I am trying to make it that when you look directly at the object, it stops moving. When you look away, it can get closer, then when you touch it, it brings you to a level called “MainMenu”. Do you know how I can do this?

Take a look at the documentation that comes with unity - its incredibly useful

As for the death, simply call Application.LoadLevel when the distance is less than 1

He said that game goes back to main menu when player touches slender man, not within specific range.

@eric56379 I suggest you to look into triggers.