var NumberEnemies : int;
var WaveNumber = 0;
var NewWave : boolean = false;
var SpawnPoints : Transform[];
var Enemies : Transform[];
var WaveGui : GUIStyle;
function Update(){
NumberEnemies = ((GameObject.FindGameObjectsWithTag("Enemy").Length) - 1);
guiText.text = "Wave: " +WaveNumber;
if(NumberEnemies == 0 !NewWave){
NewWave = true;
WaveNumber += 1;
SpawnEnemies();
}
}
function SpawnEnemies(){
for (var i = 0; i < WaveNumber; i++) {
SpawnEnemy = Instantiate(Enemies[0],SpawnPoints[0].position,SpawnPoints[0].rotation);
}
NewWave = false;
}
function OnGUI ()
{
GUI.Label (Rect (10,70,200,20), "Wave: " + WaveNumber, WaveGui);
}
How to make time break between each wave for example 30 seconds between each wave, and it will display on screen [GUI] Time to next wave 30sec and it will count down
Also when they spawn then spawn in the same place and there is like 1 enemy but inside him there is more like 5 or 10 how to make it so they spawn not in the same place
Sorry that iam not editing posts but when i click ‘EditPost’ its just blank and i cant type anything
UP
i have fix this problem but two problems above i cant figure it out please help someone
how to make breaks between wave and how to spawn more then 1 enemy on first wave
Any one can help ? i looked everywhere on google and cant find the solution ???
how to make break between wave for example 30 seconds and it will display on the screen ??
sorry i cant edit posts on this unity forum when i click edit its just blank screen i cant see anything or change.
Edit above :
this script i think will have more errors because when i set timer to 0.02 and the wave change to 2 but after this nothing happens so i will stuck with the old script with this one
var NumberEnemies : int;
var WaveNumber = 0;
var NewWave : boolean = false;
var SpawnPoints : Transform[];
var Enemies : Transform[];
var WaveGui : GUIStyle;
function Update(){
NumberEnemies = ((GameObject.FindGameObjectsWithTag("Enemy").Length) - 1);
guiText.text = "Wave: " +WaveNumber;
if(NumberEnemies == 0 !NewWave){
NewWave = true;
WaveNumber += 1;
SpawnEnemies();
}
}
function SpawnEnemies(){
for (var i = 0; i < WaveNumber; i++) {
SpawnEnemy = Instantiate(Enemies[0],SpawnPoints[0].position,SpawnPoints[0].rotation);
}
NewWave = false;
}
function OnGUI ()
{
GUI.Label (Rect (10,70,200,20), "Wave: " + WaveNumber, WaveGui);
}
can somebody help me with it ??
how to add timer between each wave ?
sorry i cant edit posts on this unity forum when i click edit its just blank screen i cant see anything or change.
Edit above :
this script i think will have more errors because when i set timer to 0.02 and the wave change to 2 but after this nothing happens so i will stuck with the old script with this one
var NumberEnemies : int = 5;
var WaveNumber = 0;
var NewWave : boolean = false;
var SpawnPoints : Transform[];
var Enemies : Transform[];
var WaveGui : GUIStyle;
var yieldTimeMax : float = 0.5;
var yieldTimeMin : float = 0.1;
var timer : float = 10.0;
function Start ()
{
waveNumber = 1;
}
function Update ()
{
NumberEnemies = ((GameObject.FindGameObjectsWithTag("Enemy").Length));
if(NumberEnemies == 0 !NewWave){
timer -= Time.deltaTime;
if(timer <= 0)
{
timer = 0;
NewWave = true;
WaveNumber += 1;
SpawnEnemies();
}
}
}
function SpawnEnemies(){
for (var i = 0; i < WaveNumber; i++) {
yield WaitForSeconds(Random.Range(yieldTimeMin, yieldTimeMax));
SpawnEnemy = Instantiate(Enemies[0],SpawnPoints[0].position,SpawnPoints[0].rotation);
}
NewWave = false;
}
function OnGUI ()
{
GUI.Box(new Rect(10, 10, 200, 20), "TimeToNextWave" + timer.ToString("0"));
GUI.Label (Rect (10,70,200,20), "Wave: " + WaveNumber, WaveGui);
}
[CODE]
Here is the old one that i will stuck with i have made timer it counts down at the begining the the wave 2 start and if i kill all enemies the 3rd start with out break ?? i have timer before 1st wave but after i have no timer what to do guys common help me
Thanks!
Why this forum is soooooo glitchy i pressed edit post and it looked like i could edit so i was suprised and i edit the post and after i finished and post it i look on this thread and see that i post another thread … whats going on ??
Look at it in the if - then manner. If i do this, then that action should happen. When you miss an if step or an action, then the action does not happen.
You miss something to count up (or down), and the code misses the reset feature then. You start with 10.0 then you need to reset back to 10.0 when done.
Let’s solve it with count up. That way you just need to change the variable, and not the code to reset the variable too …
var mytime:int=150; // the time at which the action should happen
function Update(){
timer+=1; //Always count the timer up
if(timer > mytime){ // If timer is GREATER mytime
timer = 0; //Reset the timer
NewWave = true;
WaveNumber += 1;
SpawnEnemies();
}
}
This method is of course frame dependant. Which is fine as long as the rest is also frame dependant. When you need real seconds then you have to solve it in another way. Time.time is your friend then. The manual has even an examplecode attached: Unity - Scripting API: Time.time
I would also highly suggest to use comments. That way the things becomes better structured, which saves you lots of time. And makes it clearer to yourself what step does what, and what is needed. Also, proper code formatting helps a ton.
Thanks for helping
I have update my script as you said and it looks like this now
var NumberEnemies : int = 5;
var WaveNumber = 0;
var NewWave : boolean = false;
var SpawnPoints : Transform[];
var Enemies : Transform[];
var WaveGui : GUIStyle;
var yieldTimeMax : float = 0.5;
var yieldTimeMin : float = 0.1;
var mytime : int = 150;
var timer : float = 10.0;
function Start ()
{
waveNumber = 1;
}
function Update ()
{
timer+=1; //Always count the timer up
if(timer > mytime){ // If timer is GREATER mytime
timer = 0; //Reset the timer
NewWave = true;
WaveNumber += 1;
SpawnEnemies();
}
}
function SpawnEnemies(){
for (var i = 0; i < WaveNumber; i++) {
yield WaitForSeconds(Random.Range(yieldTimeMin, yieldTimeMax));
SpawnEnemy = Instantiate(Enemies[0],SpawnPoints[0].position,SpawnPoints[0].rotation);
}
NewWave = false;
}
function OnGUI ()
{
GUI.Box(new Rect(10, 10, 200, 20), "TimeToNextWave" + timer.ToString("0"));
GUI.Label (Rect (10,70,200,20), "Wave: " + WaveNumber, WaveGui);
}
But it counts all the time and even when i dont kill all the enemies from wave 2 it just counts all the time and increase the waves and spawn them too much
How to make it so it counts only between each wave, like its 2nd wave i kill all the enemies and if there are non left it counts to 30sec and if 0 then it makes new wave and stuff ?
You have to set Newwave back to false. And for that it needs to be in the proper function. Please watch your brackets.
EDIT, hmm, now that i’m awake, it is more or less in the right position. That’s the problem with not proper formatted code. That way you easily overlook what part belongs to what.
Hmm. Try to put the NewWave false command before the spawning. I guess that the yield is making trouble here. When you wait for a second then the NewWave flag stays valid for 60 loops at a fps with 60. So first set Newwave to false, then wait, then spawn.
I would even set the timer to random instead of introducing a yield here.
“finding” scripts from others will not do the trick. You have to understand them. And the best thing to understand them is to write them from scratch. That way you will know what does what. And this is the only way to know where to modify the script to your needs.
I will definitely not fix every new script for you that you bring here now.
i know i know man
This script i had it in my assests folder for quite long i understand that script, its all what i want it works perfect except that timer on gui doesnt show up properly
I have made seperate timer in function update and if its next wave it counts from 10 and it show up on gui finally i did it now as i wanted but it works every time i change variable i need to remember to change the timer in script