被Resources.Load整崩溃了,问题如下:
1)代码1
string a = Data_Player.name; //Data_Player.name是静态变量,值等于Resources/Prefabs文件夹下文件的文件名"abc"。
Debug.Log(a); //正确显示这个文件名 "abc"
Sprite c = Instantiate(Resources.Load("Prefabs/" + a, typeof(Sprite)) as Sprite);
Debug.Log(c);
这个代码报错,提示实例化失败。
2)代码2,直接赋值文本
string a = "abc"
Sprite c = Instantiate(Resources.Load("Prefabs/" + a, typeof(Sprite)) as Sprite);
Debug.Log(c);
这个代码运行正常。
请帮忙看下这是什么情况,为什么引用静态变量不行,直接赋值就可以?
用if函数验证,Data_Player.ID 不等于 "abc", 但Debug.Log(Data_Player.ID)显示的又是 "abc"。
if (Data_Player.ID == "abc") { Debug.Log("是"); }
else { Debug.Log("否"); }
结果返回"否"。