- Home /
I'm frustrated, please help. (For cycle + instatiate)
I dont even know what's going on, i really wrote this type of code for more than 100000000x times in my projects, but know it just dont work. i use this code:
if(NincsenMindenKockaMeg == true){
for (int i = 0; i < HanyPalya; i++) {
NotSpawnedCUbe = false;
if(NotSpawnedCUbe == false){
GameObject.Instantiate(PalyaJelzo,new Vector3(-2.5f,0.5f,2+HolHagytaALapozast+Magassag),this.gameObject.transform.rotation);
NotSpawnedCUbe = true;
}
if(i == HanyPalya-1){
NincsenMindenKockaMeg = false;
}
HanyasPalya is an int which can be set for sth, i used it as 5. HolHagytaALapozast+Magassag are two floats which is added to the Vector3.z variable, to spawn the cubes on seperate positions. and my problem is, that it DOESNT SPAWN ANY CUBES!!!! What the hell man? I wrote so many codes by this time, and this little piece of sth just stopped working. Maybe it is because of Unity5 or dont know but please help me I'm desperate. PS.: I made a debugging, and the for cycle run 5 times, as i expected, the Instatiation should've happened 5 times as well, and the Quit (NincsenMindenKockaMeg = false), happened only once. But at the end of this circle, i've found no cubes at all. Please help me a fast answer would be grateful!
does it work if you use eather one of these?
(GameObject) Instantiate(PalyaJelzo,new Vector3(-2.5f,0.5f,2+HolHagytaALapozast+$$anonymous$$agassag),this.gameObject.transform.rotation);
Instantiate(PalyaJelzo,new Vector3(-2.5f,0.5f,2+HolHagytaALapozast+$$anonymous$$agassag),this.gameObject.transform.rotation) as GameObject;
Finally, i made another gameObject on the other map, so that it worked in the Start() function. But thanks, maybe I can use these codes later ;) Thank you for answering :)