Hey guys,
my current challenge is trying to instantiate “enemy” gameobjects at 2 second intervals. However, when I try to use the “waitForSecond” type function, they are simply instantiated MANY TIMES and nearly crashes unity. Ideally, my (pseudo)code would look like this:
void Update()
{
waitForSeconds(2);
gameObject.instantiate(“Enemy”);
}
Pavlon
July 3, 2015, 12:46am
2
that is what i use for the moment
using UnityEngine;
using System.Collections;
public class WaveSpawningScript : MonoBehaviour {
public GameObject spawn_point;
public int wave_size = 5;
public int mul = 1;
private float spawn_rate = 2.5f;
private float next_spawn = 0.0f;
public void Update_()
{
if(Time.time >= next_spawn && wave_size != 0)
{
SpawnMonster();
}
}
private void SpawnMonster()
{
next_spawn = Time.time + spawn_rate;
wave_size --;
GameObject monster = Instantiate(Resources.Load("Monster/Slime/SlimeMonster"),spawn_point.transform.position,Quaternion.AngleAxis(180,new Vector3(0,1,0))) as GameObject;
monster.GetComponent<Monster>().life = 20 * mul;
}
}
Update_ is called from the main loop when needed
Thanks for the help, guys!