How come this isn’t spawning more "EnemyCraft"s? The script has been saved, it is on an empty entity, it is visible by the camera
// initialize code called once per entity
EnemySpawner.prototype.initialize = function() {
// Set the initial time
this.time = 0;
// Set the time for the next enemy spawn in seconds
this.spawnNext = 1;
};
// update code called every frame
EnemySpawner.prototype.update = function(dt) {
var randomspawn = (Math.random() - 0.5) * 2;
// Set Random Position
var position = this.entity.getPosition();
this.entity.setPosition(randomspawn * 20, position.y, position.z);
this.time =+ dt;
// If 1 second has passed
if (this.time > this.spawnNext) {
this.spawnNext = this.time +1;
// Spawn Enemy
var templateAsset = this.app.assets.find("EnemyCraft");
var instance = templateAsset.resource.instantiate();
this.app.root.addChild(instance);
instance.translate(position.x, position.y, position.z);
}
};