Spawning PreScripted Objects...

What is the easiest why to go about making a Prescript-ed object spawn from a location? I have a target that has a script on it sending it from a starting location to its destination. I want to make a script that could clone this object to spawn over time to look like a crowd of targets. I heard that there is a script that could be added to control how many are on screen.

What is this script called and where can I find it to learn how to write the code out?

2 Answers

2

The easiest way to “make a Prescript-ed object spawn from a location” is to create a prefab from your object, and then write a script that instantiates as many copies of the prefab as you need.

I’m confused by your last line:

I heard that there is a script that could be added to control how many are on screen.

It sounds like your ran across a script somewhere that does crowd management? Can you tell us a bit more?

You could try this in javascript: (code from script reference)

// Instantiates 10 copies of prefab each 2 units apart from each other

var prefab : Transform;

for (var i : int = 0;i < 10; i++) {
Instantiate (prefab, Vector3(i * 2.0, 0, 0), Quaternion.identity);
}

You would drag the prefab of your prescripted object into the prefab variable.

Obviously there is other things you can do with instantiate, it doesn’t have to be 10 copies 2 units apart!!! :slight_smile:

Here is the script refernce for instantiate: http://unity3d.com/support/documentation/ScriptReference/Object.Instantiate.html

Hope this helps

-Grady