I dont know how to get string from Inputfield. I need string to post name to my scoreboard.
I tried the following code, but it gives me error: “A field initializer cannot reference the nonstatic field, method, or property `Post_score.saveField’”. Im using Unity 4.6.3
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Post_score : MonoBehaviour
{
public string addScoreURL = "http://mywebpage.com/scores/addscore.php?";
public InputField saveField;
string name = saveField.text;
int tocke = 10;
public void poslji()
{
StartCoroutine(PostScores(name, tocke));
}
IEnumerator PostScores(string name, int tocke)
{
string post_url = addScoreURL + "name=" + name + "&score=" + tocke;
WWW hs_post = new WWW(post_url);
yield return hs_post;
if (hs_post.error != null)
{
//err.text = "There was an error posting the high score: " + hs_post.error;
}
else
{
Application.LoadLevel("Menu");
}
}
}