Hello all,
I am running into an issue with the following piece of code:
function New(cn : String)
{
cardName = cn;
var cardImage : Material = Resources.Load(cardName, typeof(Material)) as Material;
gameObject.renderer.material = cardImage;
}
The code that I am using to call this is:
New(cardList[1].ToString());
where cardList is an System.Array;
When i run my code and this executes my asset does not load on the gameObject, however if i use a hardcoded string like “Joker” it will load the asset fine. I’m stuck on how to resolve this problem, any ideas?
Thanks in advance.
Debug.Log the cardname - it will work using a string, so the string must be wrong somehow. How do you populate the cardlist? Any chance there's whitespace in there (new line etc)
– whydoidoitI did a Debug.Log(cardname) and the results shows: Joker UnityEngine.Debug:Log(Object) I'm populating the cardList by parsing a text file that has the names of the cards private var cardListFile = "CardList.txt"; var sr = new StreamReader(Application.dataPath + "/" + cardListFile); var fileContents = sr.ReadToEnd(); sr.Close(); cardList = fileContents.Split("\n"[0]); Hope this helps.
– Hongard