public class flag : MonoBehaviour
{
public GameObject coin;
public int coinmax;
public float cointhrust;
public List<GameObject> coinlist = new List<GameObject>();
public void flaghit()
{
int coinnum = Random.Range(1, coinmax);
for (int i = 0; i < coinnum; i++)
coinlist.Add((Instantiate(coin, gameObject.transform.position, Quaternion.identity))as GameObject);
// access rb of all instantiated gameobject and add force
float xdir = Random.Range(-20, 20);
float ydir = Random.Range(10, 50);
Vector2 coindir = new Vector2(xdir, ydir);
}
}