- Home /
How Reset Variable After Loop
Hi, i have a custom class with a variable(rate) and this variable change after time, I want my variable back to default after my code looping
public class Wave
{
public float rate;
}
public class SpawnerPool : MonoBehaviour
{
public Wave[] waves;
public int nextWave;
void WaveCompleted()
{
waveCountdown = timeBetweenWaves;
if (nextWave + 1 > waves.Length - 1)
{
nextWave = 0;
ShowTextAnimation4();
// Reset Class Variable
}
else
{
nextWave++;
}
}
IEnumerator SpawnWave(Wave _wave)
{
// Spawn
for (int i = 0; i < _wave.count; i++)
{
if(SpawnGo)
{
if(_wave.enemyindex == 1)
{
SpawnEnemy(PoolObjectType.Enemy);
}
if(_wave.enemyindex == 2)
{
SpawnEnemy(PoolObjectType.Enemy2);
}
if(_wave.enemyindex == 3)
{
SpawnEnemy2(PoolObjectType.Enemy3);
}
if(_wave.enemyindex == 4)
{
SpawnEnemy(PoolObjectType.Enemy2);
}
yield return new WaitForSeconds(_wave.rate);
if(_wave.name == "wave1")
{
if(nextDrop >= 7)
{
if(_wave.rate > 0.3f)
_wave.rate -= 0.07f;
}
}
if(_wave.name == "wave2")
{
if(_wave.rate > 1f)
_wave.rate -= 0.04f;
}
}
}
yield break;
}
Comment
Best Answer
Answer by ShadyProductions · Mar 15, 2020 at 08:33 AM
Instead of adjusting the rate, you could keep 2 variables on the wave instead and only adjust the other variable based on the rate?
thank man, this work i appreciate you:)
public float rate; public float rate2;
IEnumerator SpawnWave(Wave _wave)
{
state = SpawnState.SPAWNING;
if(SpawnGo == false)
{
yield break;
}
// Spawn
for (int i = 0; i < _wave.count; i++)
{
if(SpawnGo)
{
if(_wave.enemyindex == 1)
{
SpawnEnemy(PoolObjectType.Enemy);
}
if(_wave.enemyindex == 2)
{
SpawnEnemy(PoolObjectType.Enemy2);
}
if(_wave.enemyindex == 3)
{
SpawnEnemy2(PoolObjectType.Enemy3);
}
if(_wave.enemyindex == 4)
{
SpawnEnemy(PoolObjectType.Enemy2);
}
yield return new WaitForSeconds(_wave.rate);
if(_wave.name == "wave1")
{
if(nextDrop >= 7)
{
if(_wave.rate > 0.3f)
_wave.rate -= 0.07f;
}
}
if(_wave.name == "wave2")
{
if(_wave.rate > 1f)
_wave.rate -= 0.04f;
}
}
}
state = SpawnState.WAITING;
// two variable
_wave.rate = _wave.rate2;
yield break;
}