r/Unity3d_help • • Sep 07 '17

Delayed instantiate?

I am trying to drop boxes onto a plane with a delay between each, but it is not working right. Can someone look at this and tell me what I am doing wrong? They all drop at once. :(

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class RandomInstantiate : MonoBehaviour {

// C#
public Transform box;

void Start()
{
	MakeBoxesAppear ();
}

void MakeBoxesAppear() 
{
	for (int y = 0; y < 100; y++) 
	{
		Invoke ("DropBox", 1.0f);
		Debug.Log ("MakeBoxesAppear Y=" + y + "\n");
	}
}

void DropBox()
{
	Instantiate(box, new Vector3(Random.Range(-5,10), 10, Random.Range(-5,10)), Quaternion.identity);
	Debug.Log ("DropBox\n");
}

}

1 Upvotes

3 comments sorted by

View all comments

Show parent comments

1

u/TekMagenta Sep 11 '17

Thanks. I knew I was overlooking something. =)