- Home /
Get array of name from file in resources
Hi! I need to get an array of strings from the list of names of the files that are located in the resources folder. example: filearray[0]=texture.png filearray[1]=3dmodel.obj
i write this code:
function Start (){
var objname : String[];
var objres : GameObject[] = Resources.LoadAll("");
Debug.Log(objres.Length);
for (i = 0; i < objres.Length; i++)
{
objname[i]= objres[i].name;
}
}
but i receive this error:
InvalidCastException: Cannot cast from source type to destination type.
any ideas?
Answer by Landern · Dec 04, 2012 at 05:13 PM
Resources.LoadAll(...) does not return an Array of GameObject, as shown in the Documentation it returns an Array of Object, this is a unity Object. You will need to cast what each object actually is and be right to gain access to the properties such as name.
Also as far as i know you need to specify a folder/directory or file name in LoadAll("/Resources/")...
ty I need to have an array filled with the names of the files in the folder resources. if it does not work with resources.loadall how can I do?
Your answer
Follow this Question
Related Questions
C# String Array Has Missing or Incorrect Keycode Strings 2 Answers
how to randomly pick a string from an array 3 Answers
C# Incrementing a String Array 1 Answer
Extending the Array class? 1 Answer