- Home /
Help with Enemy Spawner!
Hello, I am making a game where enemies spawn after 300 seconds (5min) and in 3 second intervals (each enemy appears 3sec after each other). How would I go about writing this (Java) code? I was think about putting this code on an object so the enemies spawn from that object. Please help! Thanks.
Answer by cagezero · Dec 21, 2012 at 04:20 AM
I do not use javascript much, but here is the barebones idea:
public var enemy : GameObject;
function Start () {
yield WaitForSeconds(300);
InvokeRepeating("SpawnEnemy", 3, 3);
}
function SpawnEnemy() {
//Instantiate the enemy prefab
var enemyClone : GameObject = Instantiate(enemy, Vector3.zero, Quaternion.identity);
//More code to make the enemy do stuff...
}
I moved the "var enemy : GameObject" outside of the functions. then I placed my enemy prefab I have on it. It comes up with an error: "The prefab you want to instantiate is null" how do I fix this?
Your answer
Follow this Question
Related Questions
OnMouseEnter Error 1 Answer
How do i fix this problem in my code? please help 2 Answers
Making an animation play when you press down 2 keys 1 Answer
SCRIPT NOT WORKING 2 Answers