My List only works on last element when I use it to find a path to open into my Resources folder.

I haven’t been able to figure out what is going wrong. I am passing in a random number between 1 and the .count of the list so when I continue to add more character races to the game I woun’t have to keep adding more code. The list gets its data from a text file I’m storing in Resources on one script then from another script I’m trying to pick the path where I need to load Scriptable objects. The problem is the path only works if its the last element. If someone can give my code a look and let me know where I’m going wrong it would be extremely helpful. I’m pretty new to coding, so simple explanations and easy fixes would be best. In C# would also be most helpful.

  1. This is the First Script where it makes the list.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using System.Linq;

        [RequireComponent(typeof(TextAsset))]
        public class TextInfo_Sub_Races : MonoBehaviour {
        
            public List<string> textArray;
            public TextAsset textInfo;
            [SerializeField]
    
        public string FileName = "Sub_Race_Info_text_asset";
        public List <string>  refToSubRaceTxtArray;
    
        // Use this for initialization
        private void Start()
        {
        textInfo = Resources.Load("Races_Classes_and_Base_Units/"
    
    • FileName) as TextAsset;
      //textArray = textInfo.text.Split(’
      ‘).ToList();
      textArray = textInfo.text.Split(’
      ').ToList();
      refToSubRaceTxtArray = textArray;
      }

      }

      And this is the Second
      Script

    using System.Collections; using
    System.Collections.Generic; using
    UnityEngine; using System.Linq;

    public class
    CreateNewPlayerCharacter :
    MonoBehaviour {

    private TextInfo_For_ScriptableObjects
    

    textInfoScript; // reference to
    textInfo script
    private TextInfo_Sub_Races textInfoSubRaces; // reference to
    textInfo script
    public Character_Races raceTest; // a test, delete when
    finished
    public List subRaceInfo;

    private void Awake()
    {
        textInfoScript = GetComponent<TextInfo_For_ScriptableObjects>();
        textInfoSubRaces = GetComponent<TextInfo_Sub_Races>();
    }
    
    
    private void Update()
    {
        if (Input.GetMouseButtonDown(1)) 
        {
            CreateNewCharacter();
        }
    }
    
    
    private void CreateNewCharacter()
    {
        subRaceInfo = textInfoSubRaces.textArray;
        //subRaceInfo = textInfoSubRaces.refToSubRaceTxtArray;
        int sizeOfRaceListInfo;
        sizeOfRaceListInfo = subRaceInfo.Count;
        int randomSubRace = (Random.Range(1,
    

    sizeOfRaceListInfo)); // this is
    just for getting random path in the
    races folder
    string whichSubRace = subRaceInfo[randomSubRace];

         raceTest = Resources.LoadAll<Character_Races>("Races_Classes_and_Base_Units/Races/"
    
    • whichSubRace); // this is the path which works when its the last
      element in the list

        foreach (Character_Races races in raceTest)
        {
            Debug.Log(races.name);
        }
      

      }

      }

I found the solution thanks for all your help

string whichSubRace = subRaceInfo[randomSubRace].Trim(); // needed to trim for removing the extra white spaces.