- Home /
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?
Answer by Julien-Lynge · Sep 29, 2011 at 12:09 AM
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?
Answer by Grady · Sep 29, 2011 at 12:55 AM
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!!!! :)
Here is the script refernce for instantiate: http://unity3d.com/support/documentation/ScriptReference/Object.Instantiate.html
Hope this helps
-Grady
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Random Spawn is NOT spawing Randomly,its always at SAME location ? 6 Answers
Multiple Spawn Points,Multiple Spawn Points in one scene 1 Answer
Random textures... 1 Answer
GetComponentInChildren(Renderer).active wont work? 2 Answers