- Home /
How do i make an object spawn another one?
I want to be able to make an object i have spawn a copy of another one i have. I think i have to "tag" my objects so when i code they know what im referring to? how do i do this, when i go to change my tags the generic ones come up, i cant add my own, and the script still doesn't know what im talking about. Any help would be appreciated.
Answer by robertbu · Mar 19, 2013 at 05:09 PM
For tagging, use the Tag Manager. Click on the triangle next to Tags, Increase the size, and An on the right opposite Element#, type in your tag. Then you can use the tag dropdown to set the tag for a specific object.
But to do what I think you want to do, you don't need the tag. Just use the name. Something like:
var go = GameObject.Find("ObjectName");
if (go != null)
Instantiate(go);
Note the object name has to be exactly how you name your object.
Thanks! I got the tagging down, but the actual spawning is still hard. I want to try to make a car model i have spawn an insect model and then after that make the insects change the player. The javascript i made after tagging my insect works (it lets me run the game) but im not sure if im doing it right, i have.
var enemy : GameObject; function start(){ while(true){ Instantiate(enemy,transform.position,transform.rotation); yield WaitForSeconds(1.5); } }
There are a couple of problems with your script. First "Start" function must start with a capital letter. Next, you never return from Start(). Here is an alternative:
#pragma strict
var enemy : GameObject;
function Start()
{
InvokeRepeating("Spawn", 0.0, 1.5);
}
function Spawn()
{
Instantiate(enemy,transform.position,transform.rotation);
}
Thanks heaps. I'm really new to this and my internet is really bad, so i cant look up video tutorials. I cant find a site of good text ones either.