- Home /
Enemy spawn script not working properly !
var enemy : GameObject;
var timeDelay = 3;
var ready = true;
var timer : int = 240;
var limit : int = 40;
var left : int = 40;
var grip : Transform;
function Start(){
ready = true;
if(ready){
if(timer > 0){
timer -= 1;
while (ready) {
yield WaitForSeconds(timeDelay);
Instantiate( enemy, transform.position, Quaternion.identity);
enemy.transform.LookAt(grip);
limit -=1;
enemy.transform.Translate(Vector3(0,0,1));
}
}
}
if(timer <=0){
Time.timeScale = 1;
guiText.text == "GAME OVER , HAHAHAHA !!!";
yield WaitForSeconds(3);
Application.LoadLevel("levelSelect");
}
//ENEMIES IN THIS LEVEL = 80;
if(left == 0){
guiText.text == "WELL DONE GREENHORN , YOU FINISHED LEVEL 1 ! BUT , ARE YOU READY FOR THE NEXT LEVEL !";
yield WaitForSeconds(3);
Application.LoadLevel("level2");
}
if(enemy == null){
left-=1;
}
if(limit == 0){
ready = false;
}
}
At the moment it just spawns enemies and they fly into the air ??? Help !
Could you describe your scene setup? Assu$$anonymous$$g enemy, grip and object this script is attached to are simple spheres, please write their positions. I tried to setup the scene, but can't get the effect you described. Or maybe the script is attached to grip or to enemy?
Additionally - do you really need to call LookAt and Translate methods on the original object, or on the newly created instance?
Answer by MirekPluta · Sep 12, 2013 at 07:27 PM
Instantiate( enemy, transform.position, Quaternion.identity);
Makes a copy of "enemy" and returns that copy, therefore instead of modifying "enemy" later modify that object that is returned.
Your answer
Follow this Question
Related Questions
instantiate a set amount 3 Answers
Assign the Instantiated Object to an Empty Object. 1 Answer
Issue With Spawning Enemies (javascript) 2 Answers
Machine gun script shoots all bullets at once 2 Answers
Script needs fixing ?! 1 Answer