so I'am to trying to practice in making a catch an object game in 2D c#, where I want to catch falling objects with my player object. So what I did is created an Empty GameObject and add a script to it that can spawn a falling object, problem is I don't know how to spawn it in a random place in every 2 - 3 seconds or so.
so here is my code and game view.
public class spawnball : MonoBehaviour {
public GameObject ballprefab;
GameObject ballclone;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0)) {
spawn ();
Destroy (ballclone,3);
}
}
void spawn()
{
ballclone = Instantiate (ballprefab,transform.position,Quaternion.identity)as GameObject;
}
}
above the line where I want it to randomly spawn
