- Home /
Can't get best answer.
Objects Instantiate
Hello there, am creating a game like a hidden objects. So i have many objects in a room, now i want to create objects in random. Which way is better to get this?
-Prasanna
Please, make your question more specific so someone can help. What do you want to randomize? The position? The object to spawn?
Besides, asking for the "better way" opens an often subjective discussion, and UA is not the place for that (that's what the forums are for).
And it is also better if you post your approach to solve the problem. That way you show you are doing some work ins$$anonymous$$d of asking others to do the work for you.
Use a random function to generate vector3 reference locations within required x,y,z coordinates. Then instantiate within required conditions in update if applicable the object/s you wish to spawn. It all really depends on your requirements but this is the basic idea...
Red.
@Andres Fernandez,. I have a room, in that i need to find the hidden objects, for that i need to create the objects position as random. So the objects are spawn different positions every time.
Answer by peginet · Oct 15, 2014 at 06:44 AM
Try this script : First you need create empty object and add this script.
var object1 : Transform;
var spawner : Transform;
function Update()
{
var position : Vector3 = Vector3(Random.Range(-10.0, 10.0), 0, Random.Range(-10.0, 10.0));
Instantiate(object1, spawner.transform.position + Vector3(0,20,0) + position, Quaternion.identity);
}