title: how to randomly spawn/instantiate an object everywhere in game? c#
body: <p>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.</p>
  
  <p>so here is my code and game view.</p>
  
  <pre><code>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;
  }
  
  
  }
  </code></pre>
  
  <p>above the line where I want it to randomly spawn</p>
  
  <p><a href="https://i.stack.imgur.com/8Stn7.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8Stn7.jpg" alt="above the line where I want it to randomly spawn"></a></p>