- Home /
Need help with my enemy spawn script.
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.
Answer by Cherno · Nov 18, 2013 at 12:45 AM
I would guess that it doesn't work because you disable the emily gameObject and hence it can't check if it's near the player etc.
Just use renderer.enabled = false/true (and colider.enabled = false/true) instead, this way emily will still be there and all her scripts will work in the background, but the player won't see her if she isn't supposed to be there.
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
Your answer
 
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
free roaming enemy ai 1 Answer
My Eneny AI Script Wont Work? 2 Answers
EnemyAI Script help 1 Answer
Make player not be seen by AI, when player in foilage and shadows. 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                