Question by
Creative Inventory · Sep 07, 2015 at 05:49 PM ·
spawnrandom.rangewave
Can someone help me add a wave to my Spawner script!!!
Can someone help me add a wave to my spawn script, each wave i would like it to have a certain time so it can go to the next wave and the speed can increase, i would like it to be editable in the inspector. so i can edit the time and speed. Also within my script their is a "Random.Range" function, but it is not that random, can someone help me to make it a bit more random.
Here's my spawn script:
pragma strict
// Variable to store the enemy prefab
public var enemy : GameObject;
// Variable to know how fast we should create new enemies
public var spawnTime : float = 2;
function Start() {
// Call the 'addEnemy' function every 'spawnTime' seconds
InvokeRepeating("addEnemy", spawnTime, spawnTime);
}
// New function to spawn an enemy
function addEnemy() {
// Variables to store the X position of the spawn object
// See image below
var x1 = transform.position.x - GetComponent.<Renderer>().bounds.size.x/2;
var x2 = transform.position.x + GetComponent.<Renderer>().bounds.size.x/2;
// Randomly pick a point within the spawn object
var spawnPoint = new Vector2(Random.Range(x1, x2), transform.position.y);
// Create an enemy at the 'spawnPoint' position
Instantiate(enemy, spawnPoint, Quaternion.identity);
}
Thank you!
Comment