2

How can I create dynamically objects (cubes) from one wall to the other in code in Unity? Such here: enter image description here

2 Answers 2

3

It's funny that Unity guys have written an example which looks like exactly the same thing you are trying to achieve :)

http://docs.unity3d.com/Manual/InstantiatingPrefabs.html

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you a lot :) Do you know how can I create empty space between cubes?
0

You can instantiate a prefab with 2 for sentences.

public GameObject objToCreate;

void Start ()
{
    //2 for sentences to create a vidirectional array
    for(int i = 0; i<5;i++){            //for move on Y
        for(int j = 0; j<5;j++){        //for move on X
            Instantiate(objToCreate, transform.position,transform.rotation);
            transform.Translate(1f,0,0);    //Move on X
        }
        transform.Translate(0,1f,0);    //When fill X translate on Y and start again
        transform.Translate(-5f,0,0);   //Reset out transform position 5 units as set in the first for sentence
        //For mor space between objects just change the values in Translate function
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.