Beispiel #1
0
    //Instantiate prefabs at random positions within the circle
    private void AddNewPrefabs(Vector3 center)
    {
        //How many prefabs do we want to add
        int howManyObjects = objectManager.howManyObjects;

        //Which prefab to we want to add



        for (int i = 0; i < howManyObjects; i++)
        {
            int        rand     = Random.Range(0, objectManager.prefabGO.Length);
            GameObject prefabGO = objectManager.prefabGO[rand];
            GameObject newGO    = PrefabUtility.InstantiatePrefab(prefabGO) as GameObject;

            //Send it to the main script to add it at a random position within the circle
            objectManager.AddPrefab(newGO, center);
        }
    }
    //Instantiate prefabs at random positions within the circle
    private void AddNewPrefabs()
    {
        //How many prefabs do we want to add
        int howManyObjects = objectManager.howManyObjects;

        //Which prefab to we want to add
        GameObject prefabGO = objectManager.prefabGO;

        for (int i = 0; i < howManyObjects; i++)
        {
            GameObject newGO = PrefabUtility.InstantiatePrefab(prefabGO) as GameObject;

            //To make undo work if we didn't want to add objects at these positions
            //Will actually undo all objects created in this for loop, so it's enough
            //to press ctrl+z once to undo all objects added in this loop
            Undo.RegisterCreatedObjectUndo(newGO, "Spawned Object");

            //Send it to the main script to add it at a random position within the circle
            objectManager.AddPrefab(newGO, center);
        }
    }