If Object Is In Certain Range Reset Level

I’m wondering if anyone can come up with a script where if the Object/Enemy (SlenderMan) is within a certain range (say a distance of 4) to restart the level or at least replace the player (First Person Controller) at x:278 y:2 z:401

I am one of the most hopeless scripters you’ll ever hear of, so if you can can you just give me the script and instructions and make it as simple as possible (I’m new to all scripting except applescript which is very easy).

My Objects/Players/Levels Are Called:

Player = “First Person Controller”
SlenderMan = “SlenderMan”
Level = “Slender”
XYZ = x:278 y:2 z:401



OnTriggerEnter(Collider other) {
if(other.tag == “Slender”) {
// DoRestartLevel; or
// transform.position = somex.y.z;

This should do the trick. Just write the desired trigger distance, and drag the transform you want to test for into the script in the inspector.

using UnityEngine;
using System.Collections;

public class ActionOnDistance : MonoBehaviour
  public float triggerDistance;
  public Transform target;

  void Update()
    if (Vector3.Distance(transform.position, target.position) < triggerDistance)
      // Do stuff
      Application.LoadLevel("next level name");
      // note this triggers every frame the player is close to the target
      // to only trigger once write:
      enabled = false;