Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 /
avatar image
0
Question by Animatick · Aug 04, 2015 at 07:16 AM · c#databasestrings

Convert Input Field to String

ok so ive got this code working for manual input of username and scores but i would like to use the ui input field for users to input there name....i just cant seem to figure out how to do this any help would be nice

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class Highscores : MonoBehaviour {
     
     const string privateCode = "";
     const string publicCode = "";
     const string webURL = "";
     
 
     DisplayHighscores highscoreDisplay;
     public Highscore[] highscoresList;
     static Highscores instance;
     
     void Awake() {
 
         highscoreDisplay = GetComponent<DisplayHighscores> ();
         instance = this;
     }
     
     public static void AddNewHighscore(string username, int score) {
 
         instance.StartCoroutine(instance.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");
             DownloadHighscores();
         }
         else {
             print ("Error uploading: " + www.error);
         }
     }
     
     public void DownloadHighscores() {
         StartCoroutine("DownloadHighscoresFromDatabase");
     }
     
     IEnumerator DownloadHighscoresFromDatabase() {
         WWW www = new WWW(webURL + publicCode + "/pipe/");
         yield return www;
         
         if (string.IsNullOrEmpty (www.error)) {
             FormatHighscores (www.text);
             highscoreDisplay.OnHighscoresDownloaded(highscoresList);
         }
         else {
             print ("Error Downloading: " + www.error);
         }
     }
     
     void FormatHighscores(string textStream) {
         string[] entries = textStream.Split(new char[] {'\n'}, System.StringSplitOptions.RemoveEmptyEntries);
         highscoresList = new Highscore[entries.Length];
         
         for (int i = 0; i <entries.Length; i ++) {
             string[] entryInfo = entries[i].Split(new char[] {'|'});
             string username = entryInfo[0];
             int score = int.Parse(entryInfo[1]);
             highscoresList[i] = new Highscore(username,score);
             print (highscoresList[i].username + ": " + highscoresList[i].score);
         }
     }
     
 }
 
 public struct Highscore {
     public string username;
     public int score;
     
     public Highscore(string _username, int _score) {
         username = _username;
         score = _score;
     }
     
 }

[1]: http://dreamlo.com/

Comment
Add comment · Show 5
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
avatar image jmgek · Aug 14, 2015 at 11:33 PM 1
Share

We need to ask us a specific things for us to help, try not to just paste your entire code and ask how to fix a random thing to it.

You will need to drag in a text UI and assign a var to it and change with get GetComponent()

http://answers.unity3d.com/questions/777335/46-ui-changing-the-text-component-via-script.html

avatar image Animatick · Aug 14, 2015 at 11:43 PM 0
Share

i apoligize im new to posting questions here.... to mannually upload a score i user the awake funtion like below but i would like to user userinput ins$$anonymous$$d

   public Awake()
   {
        AddNewHighscore("Ryan",500);
   }

  

   public static void AddNewHighscore(string username, int score) 
   {           

instance.StartCoroutine(instance.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");
              DownloadHighscores();
          }
          else {
              print ("Error uploading: " + www.error);
          }
      }





avatar image jmgek · Aug 14, 2015 at 11:50 PM 0
Share

No problem, So if I understand your question correct you want to upload the score when a user inputs their name?

You are using UI anyways? Why not just use their button functions ins$$anonymous$$d so when a player inputs their name and clicks a button you can pass their name and score as an argument to whatever function you want.

https://unity3d.com/learn/tutorials/modules/beginner/ui/ui-events-and-event-triggers

Once you create a button in unity and assign the call function when a user presses down you can call AddNewHighscore You just have to make the function public and have the class attached to the object. Either way watch the video.

From there you can make anything: public void AddNewHighscore(string userName, int Score) { //Upload score and name }

avatar image Animatick · Aug 15, 2015 at 12:03 AM 0
Share

yes that is what im trying to do everything i have tried has not worked for instance in android when i pass user input i do something like

String username = userName.getText.toString;

is it sorta the same for unity user input?

avatar image jmgek · Aug 15, 2015 at 12:07 AM 0
Share

Oh, Okay I am not too familiar with android string formatting but you can try String username = userName.toString();

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Why is get_url adding an extra 'http://'? -- DB request fail 1 Answer

Updating variables from dictionary database in edit mode C# 0 Answers

How can i create [n] prefabs taking Array data? 1 Answer


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