- Home /
How to instantiate multiple prefabs in multiple positions?
Hey there! I'm kinda new to Unity so here I am asking my first question :)
I've searched through many "instantiate prefabs" topics, but no one really worked for me. The thing is: I have a cube (more like a plane) with a texture. I transformed it in a prefab. In my game I can shoot thunders to houses, and the idea is to instantiate this prefab (which I call burnedGround) whenever a house is destroyed, as if the location has been burned or whatever.
So I have a javascript script called "Raios".
function OnCollisionEnter (quem: Collision)
{
//[...]
else {
Instantiate(fx_anulado, transform.position, Quaternion.identity);
Destroy (gameObject);
Destroy (quem.gameObject);
}
This is basically the code that makes the houses go down. My idea, then, was to make another javascript called "controlGround", make a function to take the X and Z of the house before it goes down and instantiate "burnedGround".
I wrote a javascript like this:
static function castBurnedGround(float x, float z){
Instantiate(burnedGround, Vector3(x, 10, z), transform.rotation);
}
And in the previous code I attached I added one line
controlGround.castBurnedGround(quem.transform.position.x, quem.transform.position.y);
I put this right after the "else", so there's no problem with the "Destroy (quem.gameObject)" there. The thing is: the console always say "Unexpected Token: x." and "Unexpected token: y." in controlGround. Even if I put this code on other scripts, it still doesn't work! I'm honestly beginning the get frustrated here :( anyone can help?
Oh, also, if anyone can bring a better solution to instantiate these prefabs, please speak up! I'd be really grateful :)
Thanks for reading!