Ok so I made the changes to the script as follows:
#pragma strict
var emily : GameObject;
var emilyspottedSound : AudioClip;
var target : Transform;
var safeDistance = 10; //How close the player can get
function Start () {
renderer.enabled = false;
collider.enabled = false;
}
function Update(){
//check how close the player is
var distanceToPlayer = Vector3.Distance(this.transform.position, target.transform.position);
// this checks to see if the player is too close then runs the spawn function
if(distanceToPlayer <= safeDistance){
spawn();
}
if (renderer.enabled == true){
destroy();
}
}
//this is your spawn function
function spawn (){
//look at the target
renderer.enabled = true;
collider.enabled = true;
transform.LookAt(target);
audio.Play();
}
function destroy(){
yield WaitForSeconds (0.5);
Destroy(gameObject);
}
It unfortunately still doesn’t work. She just stands there lol.
Thank you I will close this question as i now understand alot more about my coding. I now feel silly for the question in the first place lol
– shortyzsly