samedi 29 juin 2019

Unable to get a list with reflection using list name as string

I want the new list called classAssets to be a copy of the list that has the name of the parameter.

private List<Transform> noviceAssets = new List<Transform>();

public void ActivateClassAssets(string className) {
    string listName = className.ToLower() + "Assets";

    List<Transform> classAssets = new List<Transform> 
    ((List<Transform>)GetType().GetProperty(listName).GetValue(this, null));

    for(int i = 0; i < classAssets.Count; i++) {
        classAssets[i].gameObject.SetActive(true);
    }
}





Aucun commentaire:

Enregistrer un commentaire