I’m trying to make when i reach certains time of play,instantiate objects at a point,but because update() dont run at a steady pace i can’t use a exact number and =,so i have to use > but the objects keep appearing,i cant use a bool because i will use this for dozens of diferrent objects
void Update () {
if(Time.timeSinceLevelLoad > 5.0) {
Instantiate(newObject, transform.position, transform.rotation);
kill this script;
}
if(Time.timeSinceLevelLoad > 10.0) {
Instantiate(newObject, transform.position, transform.rotation);
kill this script;
}
Do you know how to use coroutines? Because you could spawn a bunch of coroutines in your Awake script. They only run once and you can make them delay for however long you need.
http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.StartCoroutine.html
Adding to @mweldon answer:
void Awake()
{
StartCoroutine( SpawnObjectAfterDelay( objprefab, 5.0f ) );
StartCoroutine( SpawnObjectAfterDelay( objprefab, 10.0f ) );
}
IEnumerator SpawnObjectAfterDelay( GameObject objToBeSpawned, float delay )
{
yield return new WaitForSeconds( delay );
Instantiate( objToBeSpawned, transform.position, transform.rotation );
}
Or if you want your object to appear one after another, you can use coroutines in the Start method instead of Awake:
IEnumerator Start()
{
yield return StartCoroutine( SpawnObjectAfterDelay( objprefab, 5.0f ) );
yield return StartCoroutine( SpawnObjectAfterDelay( objprefab, 5.0f ) );
}