HELP ! Highscore name input after each Death
Hi, Guys I am having a problem with my endless runner game, what I am trying to have is that after each time you die in the game it prompts you to input your name or initials that will set the username string every time.
so whoever is playing can input their initials and it will be set beside there score when uploaded.
At the moment all I have is one string variable username = "him"; but basically I want this to be set differently each time.
This the code I have so far for it. I am trying to get an input field to prompt on player death and then do my usual upload score method. any help would be greatly appreciated as I'm am pretty new to unity
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class GameplayController : MonoBehaviour {
/*********************************************************************************/
const string privateCode = "Lue5PnQTNUqjhU4Z3LT6Ywn87duzf2Lk67IgJpjGH0Tw";
const string publicCode = "59f9c90a6b2b65dd70927a7a";
const string webURL = "http://dreamlo.com/lb/";
private string username = "him";
public InputField mainInputField; //declaring input field
//public Highscore[] highscoresList;
public void AddNewHighscore(string username, int score) {
StartCoroutine(UploadNewHighscore(username,score));
}
IEnumerator UploadNewHighscore(string username, int score) {
WWW www = new WWW(webURL + privateCode + "/add/" + WWW.EscapeURL(username) + "/" + score);
yield return www;
if (string.IsNullOrEmpty(www.error))
print ("Upload Successful");
else {
print ("Error uploading: " + www.error);
}
}
/**************************************************************************************/
[SerializeField]
private GameObject pausePanel;
[SerializeField]
private Button restartGameButton;
[SerializeField]
private Text scoreText, pauseText;
private int score;
void Start () {
scoreText.text = score + "M";
StartCoroutine (CountScore());
}
IEnumerator CountScore() {
yield return new WaitForSeconds(0.6f);
score++;
scoreText.text = score + "M";
StartCoroutine (CountScore());
}
void OnEnable() {
PlayerDied.endGame += PlayerDiedEndTheGame;
}
void OnDisable() {
PlayerDied.endGame -= PlayerDiedEndTheGame;
}
void PlayerDiedEndTheGame() {
username = mainInputField.text = "Enter Text Here..."; // trying to get input field to pop up
AddNewHighscore(username,score); // call add new high score method which works fine already
pauseText.text = "Retry";
pausePanel.SetActive (true);
restartGameButton.onClick.RemoveAllListeners ();
restartGameButton.onClick.AddListener (() => RestartGame());
Time.timeScale = 0f;
}
public void PauseButton() {
Time.timeScale = 0f;
pausePanel.SetActive (true);
restartGameButton.onClick.RemoveAllListeners ();
restartGameButton.onClick.AddListener (() => ResumeGame());
}
public void GoToMenu() {
Time.timeScale = 1f;
Application.LoadLevel ("MainMenu");
}
public void ResumeGame() {
Time.timeScale = 1f;
pausePanel.SetActive (false);
}
public void RestartGame() {
Time.timeScale = 1f;
Application.LoadLevel ("Gameplay");
}
}
public struct Highscore {
public string username;
public int score;
public Highscore(string _username, int _score) {
username = _username;
score = _score;
}
}
Your answer
Follow this Question
Related Questions
C# Unity dot syntax exercise correct solution? 1 Answer
Script problem: Trying to make the code of this script run at a set interval (GUI handle object) 1 Answer
How to get variables of a behavior tree with RAIN AI 0 Answers
How to find what keys are mapped to the input buttons? 0 Answers
Dreamlo Leaderbord issue 0 Answers