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 /
avatar image
0
Question by m0mohy92 · Feb 10, 2019 at 07:55 AM · mobileinputfieldtextfile

How to save text file with the entered text in the username's input field?

Hi everyone, i created a text file in which i will save the player data; name, age, score, etc... I save the username as entered in the input field, is there anyway to save the file with that name entered in the input field text, so when i load it i know its name easily.

Comment
Add comment · Show 3
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 Hellium · Feb 10, 2019 at 11:00 AM 0
Share

Of course it is possible. Supposing you use File.WriteAllText or File.WriteAllLines, you just have to provide the content of the input field as first argument (without forgetting to append the file extension)

 File.WriteAllText( inputfield.value + ".txt", content );

Please, provide the code you currently have for an answer fitting your needs.

avatar image m0mohy92 Hellium · Feb 10, 2019 at 04:38 PM 0
Share

I got it i try to pass the value entered in the input field in start function, so there is no response. here are the code lines :- void Start() { $$anonymous$$yText = usernameInput.text.ToString (); f = new FileInfo(Application.persistentDataPath + $$anonymous$$yText + ".txt"); if(username != null) usernameInput.text = username; } is there any idea for rena$$anonymous$$g the file outside start function?

avatar image Hellium m0mohy92 · Feb 10, 2019 at 04:43 PM 0
Share

This isn't the code used to save nor load the data.

I guess you just have to move the code from the Start function to your Save function, before writing the content of the file.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Samuel014 · Feb 10, 2019 at 10:52 AM

Hi, this is my first answer so sorry if I'm wrong. To save strings u can do this:

 public string username;
 
 void Start() { // function where you want to load
 
  LoadUsername();
 }
 
 void SaveUsername() { // Here we define the function to save the username
 
     PlayerPrefs.SetString("username", username); 
   }
 
 void LoadUsername() { // Here we define the function to load the username
 
   username = PlayerPrefs.GetString("username");
 }
 
 void SaveHere() { // function where u want to save
 
  SaveUsername();
 }
Comment
Add comment · Show 2 · Share
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 blueshark- · Feb 10, 2019 at 12:31 PM 0
Share

This works in general but it's not a good thing to use this a lot of times in a short amount of time. There's other ways like JSON or Binary but this should do the work as well.

avatar image m0mohy92 · Feb 10, 2019 at 04:40 PM 0
Share

Thanks for answer. I know how to save inputfield data, i ask about how to rename the text file with the player name entered in the input field? Regards.

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

150 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

Related Questions

Keep input field caret active when focused on mobile devices in addition to native input field caret 0 Answers

How to prevent keyboard from showing in Android. 1 Answer

Mobile Keyboard Scales Screen 1 Answer

TMP InputField does not fire onTouchScreenKeyboardStatusChanged event when keyboard becomes visible 0 Answers

Disabling the inputfield above the keyboard or disable it all 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