Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by gtonra89 · Nov 02, 2017 at 09:12 AM · unity 5scripting probleminputscripting beginnerguitext

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;
     }
 
 }

  
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

242 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges