GetComponent不适用于Unity 5.2

时间:2015-11-29 18:09:42

标签: c#

我正在尝试按照本教程http://wiki.unity3d.com/index.php?title=Server_Side_Highscores

进行操作

但它尚未更新到Unity 5.2,无论我尝试什么,我都无法使GetComponent工作。

 IEnumerator GetScores()
 {
 GameObject text = new GameObject ("Loading Scores");
 text.GetComponent<GUIText>();
 WWW hs_get = new WWW(highscoreURL);
 yield return hs_get;

 if (hs_get.error != null)
 {
     print("There was an error getting the high score: " + hs_get.error);
 }
 else
 {
     GetComponent<GUIText>(hs_get.text); //Line of code not working
           // this is a GUIText that will display the scores in game.
 }
}

错误是:Assets / HSController.cs(46,25):错误CS0308:非泛型方法`UnityEngine.Component.GetComponent(System.Type)'不能与类型参数一起使用

我似乎无法让GetComponent工作任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

你试过吗

:(

我不完全确定您的代码应该做什么,但我不知道您为什么要使用GetComponent。如果您不想重复使用&#34; text&#34;变量,然后你可以尝试像

这样的东西
text.text = hs_get.text;

我不知道我是否正在解决这个问题,但我希望这有帮助!