Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Seventh Stealth · May 07, 2014 at 04:24 PM · string

How do you set a string while in game ?

Wagwan ,

I want the player to set a string while in the game and then to save it to PlayerPrefs but I'm not sure on how to prompt the player to do this and how to display a text box to write it in ? Could somebody offer advice ?

Thanks Stealth

Comment
Add comment · Show 1
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 Lo0NuhtiK · May 07, 2014 at 04:25 PM 1
Share

http://unity3d.com/learn/documentation

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by sarcasteak · May 07, 2014 at 04:31 PM

See this:

 var stringToEdit : String = "Hello World";
     function OnGUI () {
         // Make a text field that modifies stringToEdit.
         stringToEdit = GUI.TextField (Rect (10, 10, 200, 20), stringToEdit, 25);
     }

http://docs.unity3d.com/Documentation/ScriptReference/GUI.TextField.html

Comment
Add comment · 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
0

Answer by Dazdingon · May 07, 2014 at 06:01 PM

alternative method (not using OnGUI)

Use this code to get input from the player : public var displayText : String = "";

 function GetInputText () {
 
     //Get characters one by one from input
     for(c in Input.inputString){
 
         //Ignore multi-line input
         if(c == "\n"[0] || c == "\r"[0]){
             continue;
         }
         //Handle backspase manualy
         if(c == "\b"[0]){
             if(displayText.Length > 0){
                 displayText = displayText.Substring(0, displayText.Length - 1);
             }
         }
         //Add character recieved from input
         else{
         displayText += c;
         }
     }
 }

You can then display the text with something like this : public var displayObject : TextMesh;// or GUIText

 function DisplayText () {

     displayObject.text = displayText;

     //Add a blinking text cursor for fun
     if(Time.time % 1 > 0.5)displayObject.text += "_";

 }

This works with both TextMesh(3DText) and GUIText

Save displayText into your PlayerPrefs (e.g. when enter is pressed)

Comment
Add comment · Show 1 · 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 Dazdingon · May 07, 2014 at 06:45 PM 0
Share

Use TouchScreen$$anonymous$$eyboard for mobile.

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

23 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

Related Questions

replacing a character in a String 1 Answer

returning a variable in javascript 1 Answer

set Strings parts in different colors 1 Answer

www.data and string conversion to integer 2 Answers

Using the StartsWith function in a Switch Case Statement 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