How can I load a scene when the enemy hits the player?

Here’s my script. Is there a way to start a new scene start as soon as the enemy hits the player?

   var target : Transform;    
    var lookAtDistance = 20.0;
    var attackRange = 15.0;
    var moveSpeed = 20.0;
    var damping = 6.0;
    private var isItAttacking = false;
 
    function Update () 
    {
    distance = Vector3.Distance(target.position, transform.position);
 
    if(distance < lookAtDistance)
    {
    isItAttacking = false;
    renderer.material.color = Color.white;
    lookAt ();
    }   
    if(distance > lookAtDistance)
    {
    renderer.material.color = Color.white; 
    }
    if(distance < attackRange)
    {
    attack ();
    }
    if(isItAttacking)
    {
    renderer.material.color = Color.red;
    }
}
 
function lookAt ()
{
var rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
}
 
function attack ()
{
    isItAttacking = true;
    renderer.material.color = Color.red;
    transform.Translate(Vector3.forward * moveSpeed *Time.deltaTime); 
}

Is there a way to make a new scene start as soon as the enemy hits the player?

Yes. Use collision detection to determine when the enemy hits the player, and use Application.loadLevel to change scene.

@gsaccone101 Collision Detection is a Component. Add the componnet on what you want to not go through. I suggest, for 2D OR 3D, use the component Mesh Collider.

Just use OnTriggerEnter to detect the collision, then use Application.LoadLevel to load another scene. Read the docs for those 2, they are basics of Unity and very easy but essential to use.

It’s easy follow this steps :-

void OnCollisionEneter (collision other)
{
if (other.colider.tag == "Enemy Shot")
{
SceneManager.LoadScene ("Scene Name Or Index");
}
}

don’t forget to write using UnityEngine.SceneManagement; in the up of the script if you are using unity 5.3
if not, use Application.LoadLevel ("Scene Name Or Index");

var target : Transform;
var lookAtDistance = 20.0;
var attackRange = 15.0;
var moveSpeed = 20.0;
var damping = 6.0;
private var isItAttacking = false;

private int currentLevel;

function Start () {
// This is the current scene you are in and have built in build settings
     	currentLevel = Application.loadedLevel;
}
  
     function Update () 
     {
     distance = Vector3.Distance(target.position, transform.position);
  
     if(distance < lookAtDistance)
     {
     isItAttacking = false;
     renderer.material.color = Color.white;
     lookAt ();
     }   
     if(distance > lookAtDistance)
     {
     renderer.material.color = Color.white; 
     }
     if(distance < attackRange)
     {
     attack ();
     }
     if(isItAttacking)
     {
     renderer.material.color = Color.red;
     }
 }
  
 function lookAt ()
 {
 var rotation = Quaternion.LookRotation(target.position - transform.position);
 transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
 }
  
 function attack ()
 {
     isItAttacking = true;
     renderer.material.color = Color.red;
     transform.Translate(Vector3.forward * moveSpeed *Time.deltaTime); 

// This will reload the scene you are currently on.  If you would like to load the next scene you would say Application.LoadLevel (currentLevel + 1);
Application.LoadLevel (currentLevel);
 }