I am trying to transfer objects from the array to instantiate, everything seems to be written correctly, there are no launch errors, but also tell me the expected result, why?

using UnityEngine; using System.Collections; public class mapGenirator : MonoBehaviour { public enum ListBlock { Mpole1, Mpole2 } public Transform SB_Mpole1; public Transform SB_Mpole2; public Transform ground; Transform ReturnList (ListBlock RL) { switch (RL) { case ListBlock.Mpole1: return SB_Mpole1; case ListBlock.Mpole2: return SB_Mpole2; default: return SB_Mpole1; } } ListBlock [,] ArrayListBlock; void createlevel() { for (int i = 0; i < 10; ++i) { for (int j = 0; j < 10; ++j) { float PositionBlock_x = transform.position.x + SB_Mpole1.localScale.x; float PositionBlock_z = transform.position.z + SB_Mpole1.localScale.z; float PositionBlock_y = transform.position.y + 10f; Transform AddArrey = ReturnList( ArrayListBlock[i, j]); Transform createBlock = (Transform)Instantiate(SB_Mpole1, new Vector3(PositionBlock_x, PositionBlock_y, PositionBlock_z), Quaternion.identity); } } } void fullArrey () { for (int i = 0; i < 10; ++i) { for (int j = 0; j < 10; ++j) { ArrayListBlock[i,j] = ListBlock.Mpole1; } } } void Sharing() { fullArrey(); createlevel(); } void start () { createlevel(); ArrayListBlock = new ListBlock[10,10]; } } 

Closed due to the fact that the essence of the question is incomprehensible by the participants of PashaPash , Visman , Vladimir Glinskikh , MAXOPKA , Regent 11 Sep '15 at 4:47 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • There is no expected result - this is, of course, a serious description of the problem. Sort all the functions, find out if the arguments you are expecting come to them and if they give you the values ​​you expect. When each of your functions will behave in the way you expect, then the whole program will be. - VladD
  • Offtopic: I think that one? if every braces? first raise up to the declaration of the method / class / etc, then the entry will be slightly shorter and not much damage the codestyle? - Gena Tsarinny
  • 3
    > if every braces? first raise up to the declaration of the method / class / etc, then the entry will be slightly shorter and not much damage the codestyle? You have such a whole sect, so not one. And this, by the way, is one of the key aspects of the coding style. - nitrocaster

2 answers 2

I would have done a bit wrong.

Would create an array of objects

 public Transform[] prefabs; 

And then I would instantiate it

 Instantiate(prefabs[Random.Range(0, prefabs.Length)], new Vector3(i * 2.0F, 0, 0), Quaternion.identity); 

An object from the array will now be randomly instantiated

Note work with Instantiate in units. The problem is what I do not understand, but the essence seems to have caught, my version is this.

    You have start() with a small letter "s". This is a missprint? If so conceived, your code is simply not invoked.

    In order for the method to be called by the engine, it is necessary to implement the MonoBehaviour.Start() method:

     void Start () { createlevel(); ArrayListBlock = new ListBlock[10,10]; } 
    • @ Dmitry some more logic) - Nick Volynkin
    • @NickVolynkin edited the world. Now everything is very logical. :) - Dmitriy
    • In this case, you do not need to do any override. You yourself showed the code without overloading the method and this is correct. But the answer is not formulated correctly. Unity uses a messaging system to call these methods. - vmp1r3