Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 garasouleima01 · Jun 25, 2019 at 12:49 PM · unity 5textinputfieldsplit

start counting number of line in input field after a specific line and read it

Hello, I'm new in unity and i'm making a game to test programming skill something like codecombat and i have a question please i want to start counting the lines in a input field after a specific line for example i have a input field that have this lines
Hero.left(2)
Hero.right(2)
REPEAT
{
Hero.Down(3)
}

i want it if he find this word "REPEAT" to start counting the number of line from "{" to "}" (counting the number of lines inside the " { } " and read it ).
this is my all the code in the script that i'm using

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class GameManager1_4 : MonoBehaviour
 {
     public InputField mainInputField;
     //public float speed;
 
     public GameObject Player;
     public Button Click_me;
 
     public float smoothing = 1f;
     public Transform TargetRight;
     public Transform TargetRight1;
     public Transform TargetRight2;
     public Transform TargetDown;
     public Transform TargetDown1;
     public Transform TargetDown2;
 
     int count;
     public float targetTime = 2f;
     private readonly Queue<Transform> _commands = new Queue<Transform>();
     // Start is called before the first frame update
     void Update()
     {
         targetTime -= Time.deltaTime;
         if (targetTime <= 0.0f)
         {
             targetTime = 0f;
             timerEnded();
         }
 
     }
     public void SubmitName()
     {
         int countligne = 0;
         var lines = mainInputField.text.Split('\n');
       //  mainInputField.text = "";
         foreach (var line in lines)
         {
             countligne++;
           
             switch (line.ToUpper())
             {
                 case "REPEAT(3)":
                     for (int i = 0; i < 3; i++)
                     {
                         var lines_reapeat = mainInputField.text.Split('\n');
                         Debug.Log(lines_reapeat);
                         foreach (var line_rep in lines_reapeat)
                         {
                             switch (line_rep.ToUpper())
                             {
                                 case "DOWN(1)":
                                     // adds a new item to the end of the Queue
                                     _commands.Enqueue(TargetDown);
                                     break;
                                 case "RIGHT(1)":
                                     _commands.Enqueue(TargetRight);
                                     break;
                                 case "}":
 
                                     break;
                             }
                         }
                     }
                     //i want this line to start calculation from "{" to "}" and run the right donw command inside the "{" "}" but it's always calculating the same inputfieald 
                       
                    
                     break;
                 case "DOWN(1)":
                     // adds a new item to the end of the Queue
                     _commands.Enqueue(TargetDown);
                     break;
                 case "RIGHT(1)":
                     _commands.Enqueue(TargetRight);
                     break;
             }
 
 
 
 
 
 
         }
         StartCoroutine(WorkCommands());
         mainInputField.text = "";
     }
 
     private IEnumerator WorkCommands()
     {
         // block input
         Click_me.interactable = false;
 
         // run this routine until all commands are handled
         while (_commands.Count > 0)
         {
             // returns the first element and at the same time removes it from the queue
             var target = _commands.Dequeue();
 
             // you can simply yield another IEnumerator
             // this makes it execute and at the same time waits until it finishes
             yield return MovementCoroutine(target);
         }
 
         // when done allow input again
         Click_me.interactable = true;
         CountNumbre();
     }
     // Update is called once per frame
 
 
 
     private IEnumerator MovementCoroutine(Transform target)
     {
         var startPos = Player.transform.position;
         var targetPos = target.position;
        
         var timePassed = 0f;
 
         do
             {
                 var lerpFactor = Mathf.SmoothStep(0, 1, timePassed / smoothing);
                 Player.transform.position = Vector3.Lerp(startPos, targetPos, lerpFactor);
 
                 timePassed += Time.deltaTime;
 
                 yield return null;
             }
             while (timePassed < smoothing);
             Player.transform.position = targetPos;
 
         
 
 
         // just to be sure there is no over or undershooting
         // in the end set the correct target position
 
     }
     void CountNumbre()
     {
         count++;
 
         var startPos = Player.transform.position;
      
         var timePassed = 0f;
       
             Debug.Log("Nombre de fois" + count);
 
         if (count >= 3)
         {
             Click_me.interactable = false;
 
             Debug.Log("You finish all your chance");
         }
     }
     void timerEnded()
     {
         if (Player.transform.position == TargetRight2.position)
         {
             Debug.Log("Processing Speed = 100");
             Application.Quit();
         }
         else
         {
             Debug.Log("Processing Speed = 0");
         }
     }
 }
 


and this is the function i use in splitting lines and read what the player has been write

 public void SubmitName()
     {
         int countligne = 0;
         var lines = mainInputField.text.Split('\n');
       //  mainInputField.text = "";
         foreach (var line in lines)
         {
             countligne++;
           
             switch (line.ToUpper())
             {
                 case "REPEAT(3)":
                     for (int i = 0; i < 3; i++)
                     { //i want this line to start calculation from "{" to "}" and run the right donw command inside the "{" "}" but it's always calculating the same inputfieald 
                         var lines_reapeat = mainInputField.text.Split('\n');
                         Debug.Log(lines_reapeat);
                         foreach (var line_rep in lines_reapeat)
                         {
                             switch (line_rep.ToUpper())
                             {
                                 case "DOWN(1)":
                                     // adds a new item to the end of the Queue
                                     _commands.Enqueue(TargetDown);
                                     break;
                                 case "RIGHT(1)":
                                     _commands.Enqueue(TargetRight);
                                     break;
                                 case "}":
 
                                     break;
                             }
                         }
                     }
                    
                       
                    
                     break;
                 case "DOWN(1)":
                     // adds a new item to the end of the Queue
                     _commands.Enqueue(TargetDown);
                     break;
                 case "RIGHT(1)":
                     _commands.Enqueue(TargetRight);
                     break;
             }
 
 
 
 
 
 
         }
         StartCoroutine(WorkCommands());
         mainInputField.text = "";
     }

please anyone can help me in this i'm stuck and sorry for my English.

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

207 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

Related Questions

Inputfield text to String variable 1 Answer

Public text to multi line 1 Answer

Unity 5 input field unable to store user input 1 Answer

Input Fields not actually taking in user data on android build 0 Answers

Getting pixel font to look decent 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