how to make 3d objects appear randomly?

i am doing a cooking game wherein the user have to find the ingredients of a certain dish in the kitchen, i have to make the objects appear randomly every time the scene will load…how can i do that?pleaaasssee…thanks.

You could do this a few ways depending on how you want to do it. If you are looking to have the Objects appear randomly at any set of coordinates in a given area, you could just do something like this:

var object : GameObject;
private var x : float;
private var y : float;
private var z : float;

function Start (){
      x = (Random.Range(-50.0, 50.0);
      y = (Random.Range(-50.0, 50.0);
      z = (Random.Range(-50.0, 50.0);
      Instantiate (object, Vector3(x,y,z), Quaternion.identity);
}

Or, if you wanted to have it randomly spawn at one of a certain number of points, you could do something like this:

var object : GameObject;
var points : Vector3[] = new Vector3[10];

function Start(){
      Instantiate (object, points[Random.Range(0, 9)], Quaternion.identity);
}

Just keep in mind that you would have to give it all of the points that you wanted things to spawn.

Hope this helps.

I’m assuming you have a set of different places in the kitchen where ingredients are stored. And each time you run the game you want to shuffle up what ingredient is stored in each place. Start with an array of positions for ingredients. Then shuffle them. The simplest shuffling algorithm randomly picks two elements in the array and swaps them. It repeats this swapping a number of times appropriate to the size of the array.

If you are looking for a more general solution for placing items in a particular rectangular, circular, or spherical area, See Random.Range(), Random.insideUnitCircle, and Random.insideUnitSphere.