3Dmajid
3Dmajid

Reputation: 77

Get Asset Folder Path On Android (Unity3D)?

I work with Unity3D. I need to get Sprite folder path in my resources so I used "AssetDatabase" class to do this. but this class is depend UnityEditor refrence and can't compile on android. so I need another way to get my asset path. this is my code and work perfect, but I have to change that to compile on Android, I need to get Sprite folder name :

void makeRandomQuestion()
{
    Sprite temp = AllQuestions[Random.Range(0, AllQuestions.Count)];
    gameObject.transform.GetChild(0).gameObject.GetComponent<Image>().sprite = temp ;
    string t = AssetDatabase.GetAssetPath(temp);
    string[] m = t.Split('/');
    string c = m[2] + "/Character/char/" + temp.name;
    correctOption = Resources.Load<Sprite>(c);
}

Upvotes: 0

Views: 2167

Answers (1)

buxter
buxter

Reputation: 593

The Resources folder is a special folder which allows you to access assets by file path and name in your scripts. AssetDatabase is an editor only API. So, you just need put your assets in Resources folder and access them like this:

correctOption  = Resources.Load<Sprite>("pathToAssetInResourcesFolder");

Upvotes: 1

Related Questions