- Home /
How to change scripts to include Waves of Enemy?
Spawn script, 2nd script is Score managing script.
var spawnPoints : Transform[]; // Array of spawn points to be used.
var enemyPrefabs : GameObject[]; // Array of different Enemies that are used.
var amountEnemies = 1000; // Total number of enemies to spawn.
var yieldTimeMin = 2; // Minimum amount of time before spawning enemies randomly.
var yieldTimeMax = 5; // Don't exceed this amount of time between spawning enemies randomly.
function Start(){
Spawn();
}
function Spawn(){
for (i=0; i<amountEnemies; i++){ // How many enemies to instantiate total
yield WaitForSeconds(Random.Range(yieldTimeMin, yieldTimeMax)); // How long to wait before another enemy is instantiated.
var obj : GameObject = enemyPrefabs[Random.Range(0, enemyPrefabs.length)]; // Randomize the different enemies to instantiate.
var pos: Transform = spawnPoints[Random.Range(0, spawnPoints.length)]; // Randomize the spawnPoints to instantiate enemy at next.
Instantiate(obj, pos.position, pos.rotation);
}
}
@script ExecuteInEditMode()
var currentScore : int = 0;
var time : float = 0.0;
var hitCrosshairTexture : Texture;
private var alphaHit : float;
var hitSound : AudioClip;
var mySkin : GUISkin;
var pointsToNextRank : int = 50;
var rank : int = 0;
var rankSound : AudioClip;
function Update () {
if (time > 0){
time -= Time.deltaTime;
}
alphaHit = time;
}
function DrawCrosshair(){
yield WaitForSeconds(0.1);
time = 1.0;
audio.PlayOneShot(hitSound, .5);
}
function addScore(value : int){
yield WaitForSeconds(0.2);
currentScore += value;
if(currentScore >= pointsToNextRank){
rank++;
PlayAudioClip(rankSound, transform.position, 1.0);
pointsToNextRank += currentScore;
}
}
function PlayAudioClip (clip : AudioClip, position : Vector3, volume : float) {
var go = new GameObject ("One shot audio");
go.transform.position = position;
var source : AudioSource = go.AddComponent (AudioSource);
source.clip = clip;
source.volume = volume;
source.pitch = Random.Range(0.95,1.05);
source.Play ();
Destroy (go, clip.length);
return source;
}
function OnGUI(){
GUI.skin = mySkin;
var style1 = mySkin.customStyles[0];
GUI.Label (Rect(40, Screen.height - 80,100,60)," SCORE :");
GUI.Label (Rect(100, Screen.height - 80,160,60),"" + currentScore, style1);
GUI.Label (Rect(40, Screen.height - 110,100,60)," LVL :");
GUI.Label (Rect(100, Screen.height - 110,160,60),"" + rank, style1);
GUI.color = Color(1.0, 1.0, 1.0, alphaHit);
GUI.DrawTexture (Rect ((Screen.width - hitCrosshairTexture.width)/2, (Screen.height - hitCrosshairTexture.height)/2, hitCrosshairTexture.width, hitCrosshairTexture.height), hitCrosshairTexture);
}
Comment
you are asking how to add waves of enemies, we have no idea what that means for your game, specifically
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
SendMessage setName has no receiver! 1 Answer
Spawn Script Not Working 1 Answer
Spawn System Troubles 0 Answers