Hey guys…
It works “ok” but there´s an error on the console that I have no idea why I am getting it, so maybe you can help me out…
it says:
Can’t add component ‘GUIText’ to GameObject because such a component is already added to the game object!
UnityEngine.GameObject:AddComponent()
c__Iterator8:MoveNext() (at Assets/Menu2/Script/Options.cs:307)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
Options:OnGUI() (at Assets/Menu2/Script/Options.cs:282)
However I did not add the GUIText before…
Here is the code:
public string highscoreURL = "http://elhosting/display.php";
public GameObject myDb;
public bool cor;
void Start()
{
lSel = PlayerPrefs.GetInt("EngSpaChi");
// myDb = GetComponent<GUIText>();
}
void OnGUI()
{
//here I have all the GUI buttons set with bools, and when one, named _highscores is true, the Coroutine starts
}
IEnumerator GetScores()
{
if (cor == true)
{
GUIText myText = myDb.AddComponent<GUIText>();
myText.transform.position = new Vector3(0.2f, 0.8f, 0f);
myText.text = "Loading Scores";
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
{
myText.text = hs_get.text; // this is a GUIText that will display the scores in game.
}
}
}
Thanks!!!