Answers for "unity how to tell how many objets are in a folder"

C#
1

unity how to tell how many objets are in a folder

void Start()
    {
        //I needed to get a count of my all level prefabs from my
        //Resources folder so I hashed together this frankenstein code:

        //Get the path of the Levels folder from Resources
        string AssetsFolderPath = Application.dataPath;
        string levelFolder = AssetsFolderPath + "/Resources/Levels";

        Debug.Log("dataPath : " + levelFolder);

        //////////////////////

        //DirectoryInfo needs "using System.IO"
        DirectoryInfo dir = new DirectoryInfo(levelFolder);
        FileInfo[] info = dir.GetFiles("*.prefab");
        int fileCount = info.Length;

        Debug.Log("Level Count: " + fileCount);

        //Clear array to save space, needs "using System"
        Array.Clear(info, 0, info.Length);
    }
Posted by: Guest on August-26-2020

Code answers related to "unity how to tell how many objets are in a folder"

C# Answers by Framework

Browse Popular Code Answers by Language