Adding a load level to this script.

var currentCell : GameObject;
var playerMovementScript : PlayerMovementScript;
var playerCell : GameObject;
var goalDoor : GameObject;
var shortestPathSoFar : float;
@HideInInspector
var waitToStart : int = 5;
var currentMoveSpeed : float = 2;

function Awake ()

{
shortestPathSoFar = Mathf.Infinity;
playerMovementScript = GameObject.FindWithTag(“Player”).GetComponent(PlayerMovementScript);
waitToStart = 5;
}

function OnTriggerEnter (hitTrigger : Collider)

{
if (hitTrigger.tag == “AIpathCell”)
currentCell = hitTrigger.gameObject;
}

function OnTriggerExit (other : Collider){

if (other.tag == "AIpathCell"){

	Statics.enemySpacesMove += 1;
}

}

function Update ()

{

if (Statics.enemyControlOn){

if(PlayerMovementScript.CrntDroneName == “TF_Sleeper1”)
{

if (Statics.enemySpacesMove < 2)
{

if (waitToStart <= 0)
{
    playerCell = playerMovementScript.currentCell;
    for (var doorCheckingNow : GameObject in currentCell.GetComponent(AIpathCellScript).doors)
    {
        for (var i : int = 0; i <= doorCheckingNow.GetComponent(AIpathDoorScript).cells.length - 1; i++)
        	{
            	if (doorCheckingNow.GetComponent(AIpathDoorScript).cells *== playerCell)*

if (doorCheckingNow.GetComponent(AIpathDoorScript).doorsToCells < shortestPathSoFar)
* {*
* goalDoor = doorCheckingNow;*
_ shortestPathSoFar = doorCheckingNow.GetComponent(AIpathDoorScript).doorsToCells*;
}
}
}
shortestPathSoFar = Mathf.Infinity;
}
waitToStart -= 1;*_

if(goalDoor && currentCell != playerCell)
_ transform.position += (goalDoor.transform.position - transform.position).normalized * currentMoveSpeed * Time.deltaTime;
* animation.Play(“sleepWalk”);
}
if (Statics.enemySpacesMove > 1){*_

* animation.Stop(“sleepWalk”);*
* //Turn_Master.currentEnemy += 1;
_ if(PlayerMovementScript.crntDrone == PlayerMovementScript.arrayLength-1){
Statics.currentTurn = “plyer”;
PlayerMovementScript.crntDrone = 0;
}
else{PlayerMovementScript.crntDrone +=1;}
Statics.enemySpacesMove = 0;
}
}
}
}*
Basically all I need is to add in a load application when this object gets close enough to the player, but where do I add in the distance variable and stuff? Do I need an else in there somewhere?_

First of all, we all are sick and tired of people not formatting their code correctly (no offense meant), and so it is a pain in the ass to attempt and read it. However, it is dead easy to load another level/scene via a trigger. So, follow these steps:

  • Add a collider to the object you want to load the level on collision from

  • Attach this simple script to it:

    void OnTriggerEnter(Collider other) {

     Application.LoadLevel("Your level's name or number");
    

    }

  • After that, make sure the object’s collider component has the “Is Trigger” switched on. (Note that this will disable collision, so you might want to add another collider for collision purposes.)

I hope that helps :slight_smile: Tell me if you need any further assistance.

John