- Home /
Question by
superluigi · Sep 24, 2018 at 07:37 AM ·
instantiatedestroy
Is it possible to create an instance of a prefab without instantiating it into the scene?
The following block of code will create 2 instances of my prefab. I can probably destroy the first instance after adding it to my list, but I'm wondering if there's a cleaner way of achieving this. I haven't been able to find anything on the scripting reference. Basically what I'm asking is: Can I create an instance of a prefab without actually instantiating it into the scene?
void Start ()
{
for (int i = 0; i < StaticScript.Hero.Count; i++)
{
GameObject instanceHero = Instantiate(StaticScript.Hero[i], transform.position, transform.rotation);
Hero.Add(instanceHero);//this is a different list by the same name. The other list is static and in a completely different script
HeroAlive.Add(StaticScript.HeroAlive[i]);// same deal with this HeroAlive list
if (HeroAlive[i] == 1)
{
Instantiate(Hero[i], transform.position, transform.rotation);
}
}
}
Comment
Answer by LCStark · Sep 24, 2018 at 08:32 AM
What are you trying to achieve here? Do you need the first Instantiate
call? Can't you simply call Hero.Add(StaticScript.Hero[i])
?
Your answer
