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 StarlingSoftworksInteractive · Feb 13, 2017 at 12:13 PM · c#unity 5unity5scripting beginner

How would you clear a string or previous text?

Hey guys, How would clear all the text? I don't really know how to do it

 public Canvas myCanvas;
     public Text myText;
     // Creates varibles to view more text
     private string display = "";
     private bool engagedText;
     List<string> textEvents;
     // Creates varibles inorder to reconised input commands
     public InputField inputfield;
     // Creates a Command string that holds commands
     private Dictionary<string, System.Action<string,string>> commands;
 
     protected void Awake()
     {
         //Holds the command string and points them to their methods and functions
         // Listen when the inputfield is validated
         commands = new Dictionary<string, System.Action<string,string>>();
         commands.Add( "help", onHelpTyped );
         inputfield.onEndEdit.AddListener( OnEndEdit );
     }
 
     void Start () {
         textEvents = new List<string>();
 
         textEvents.Add ("Welcome to my App");
         textEvents.Add ("Your currently offline (console), login to go online");
         textEvents.Add ("Type help for help");
         engagedText = true;
     }
         
     void Update () {
         if(engagedText)
         {
             AddText();
             engagedText = false;
         }
     }
         
     private void OnEndEdit( string input )
     {
         // Only consider onEndEdit if Submit (Enter/return) key being press
         if ( !Input.GetButtonDown( "Submit" ) )
             return;
 
         bool commandFound = false;
 
         // If the command is entered,it finds the correct command
         foreach ( var item in commands )
         {
             if ( item.Key.ToLower().StartsWith( input.ToLower() ) )
             {
                 commandFound = true;
                 item.Value( item.Key, input );
                 break;
             }
         }
 
         // If command is not founded, perform this task & clear the InputField
         if ( !commandFound )
             textEvents.Add ("Command not founded");
             engagedText = true;
 
             inputfield.text = "";
     }
 
     // Help function 
     private void onHelpTyped( string command, string input )
     {
         textEvents.Add ("hi");
         textEvents.Add("hello");
         textEvents.Add("mate");
         engagedText = true;
     }
 
     
    
    
 
     // Add the new text while keeping the old text.
     void AddText()
     {
         display = "";
         foreach(string msg in textEvents)
         {
             display = display.ToString () + msg.ToString() + "\n";
         }
         myText.text = display;
     }
 
  }
 
Comment
Add comment · Show 2
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 Chubzdoomer · Feb 13, 2017 at 08:39 PM 0
Share

Which text are you referring to? Could you be a bit more specific?

avatar image StarlingSoftworksInteractive Chubzdoomer · Feb 13, 2017 at 08:51 PM 0
Share

these text I mean, so basically this text showed up at the start of the game and when I type in help the next set of text shows up and now I am trying to clear all the text when the user type in "clear"

      textEvents.Add ("Welcome to my App");
      textEvents.Add ("Your currently offline (console), login to go online");
      textEvents.Add ("Type help for help");

  private void onHelpTyped( string command, string input )
  {
      textEvents.Add ("hi");
      textEvents.Add("hello");
      textEvents.Add("mate");
      engagedText = true;
  }

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Chubzdoomer · Feb 13, 2017 at 09:34 PM

If you want to clear all of the text, you can add this line below "commands.Add("help", onHelpTyped);":

         commands.Add("clear", onClearTyped);

Then create a new onClearTyped function that is as follows:

     private void onClearTyped (string command, string input)
     {
         textEvents.Clear();
     }
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 StarlingSoftworksInteractive · Feb 14, 2017 at 09:23 AM 0
Share

Thanks for your help mate. I reallyappreciate it

avatar image
0

Answer by tanoshimi · Feb 13, 2017 at 09:27 PM

textEvents is a list. So, if you want to clear it:

 textEvents.Clear();
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

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

9 People are following this question.

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

Related Questions

Must I attach every script to a gameobject in order to work ? 2 Answers

Multiple Cars not working 1 Answer

"Only assignment, call, increment, decrement and new object expressions can be used as statements" 1 Answer

How to define a slider on script file? 1 Answer

Instantiate an object each time in less time 2 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