• 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
1
Question by varan941 · Feb 04, 2020 at 01:40 PM · uiunityeditortimerecord

How to record the time of pressing the UI buttons, and repeat the press.

How to record the time of pressing the UI buttons, and repeat the press. For example: clicked on the first button (the object changed color), after 2 seconds, clicked on the second (the object increased), after a second clicked on the third (the object became as before). After he pressed a special button and all the actions were reproduced. Perhaps you know examples or plugins.

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 JPhilipp · Feb 04, 2020 at 03:35 PM 0
Share

You can e.g. add a Dictionary<float,int> clicks which records the click times (Time.time) as well as the button index (int). Alongside, a float startTime (initialized on every round via Time.time), which you later keep comparing against in your Update(). You can also have bool record which is flipped based on the state. When recording (record is true), you push new times into the list using clicks.Add(Time.time, buttonIndex). When not recording, you play it all back from the list.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by varan941 · Feb 10, 2020 at 10:59 PM

I did. Algorithm: 1.add the desired button to the script 1. add her OnClick event with the desired method from this script 3.create coroutine in the script if it is not 2. call it a separate method by pressing

 using UnityEngine;
 using UnityEngine.UI;
 
 public class Click_tracking : MonoBehaviour
 {
     //массивы для записи времени нажатий каждой кнопки
     public float[] _time; public float[] _time1; public float[] _time2; public float[] _time3; public float[] _time4; public float[] _time5; public float[] _time6; public float[] _time7; public float[] _time8; public float[] _time9; public float[] _time10;
 
     public int[] _counts; //счётчики количества нажатий
     public Button[] _button;
 
     bool _cheakTimer = false;
     public float _timer; //таймер
 
     private void Update()
     {
         _timer += Time.deltaTime;
     }
 
     public void NewMethod() // методы для фиксации времени нажатий
     {
         if (!_cheakTimer)
         {
             _time[_counts[0]] = _timer;
             _counts[0] += 1;
         }
         Debug.Log(_button[0]);  
     }
 
     public void NewMethod1()
     {
         if (!_cheakTimer)
         {
             _time1[_counts[1]] = _timer;
             _counts[1] += 1;
         }
     }
    
     public void Reproduce() // метод для запуска корутин
     {
         _cheakTimer = true;
         _timer = 0.0f;
 
         StartCoroutine("Zero");
         StartCoroutine("First");
         StartCoroutine("Second");
        
         Debug.Log("Старт корутины");
     }
 
     public IEnumerator Zero() // корутины для вызова нажатий
     {
         for (int i = 0; i < _counts[0]; i++)
         {
             if (i == 0)
             {
                 yield return new WaitForSeconds(_time[i]);
                 _button[0].onClick.Invoke();
                 Debug.Log("Есть первое пробитие");
             }
             else
             {
                 yield return new WaitForSeconds(_time[i] - _time[i - 1]);
                 _button[0].onClick.Invoke();
                 Debug.Log("Есть второе пробитие");
             }
         }
 
     }
     public IEnumerator First()
     {
         for (int i = 0; i < _counts[1]; i++)
         {
             if (i == 0)
             {
                 yield return new WaitForSeconds(_time1[i]);
                 _button[1].onClick.Invoke();
                 Debug.Log("Есть первое пробитие");
             }
             else
             {
                 yield return new WaitForSeconds(_time1[i] - _time1[i - 1]);
                 _button[1].onClick.Invoke();
                 Debug.Log("Есть второе пробитие");
             }
         }
     }
     public IEnumerator Second()
     {
         for (int i = 0; i < _counts[2]; i++)
         {
             if (i == 0)
             {
                 yield return new WaitForSeconds(_time2[i]);
                 _button[2].onClick.Invoke();
                 Debug.Log("Есть первое пробитие");
             }
             else
             {
                 yield return new WaitForSeconds(_time2[i] - _time2[i - 1]);
                 _button[2].onClick.Invoke();
                 Debug.Log("Есть второе пробитие");
             }
         }
     }
     public IEnumerator Third()
     {
         for (int i = 0; i < _counts[3]; i++)
         {
             if (i == 0)
             {
                 yield return new WaitForSeconds(_time3[i]);
                 _button[3].onClick.Invoke();
                 Debug.Log("Есть первое пробитие");
             }
             else
             {
                 yield return new WaitForSeconds(_time3[i] - _time3[i - 1]);
                 _button[3].onClick.Invoke();
                 Debug.Log("Есть второе пробитие");
             }
         }
     }    
 }



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
1

Answer by logicandchaos · Feb 04, 2020 at 04:27 PM

You just need variables to keep track of when you press buttons. I would probably put it all in a class. Like have an action class and then have a float timePressed in it. Then you can keep track of when every action was executed and you can make a recording of it by putting it in a list. Then you execute it based on your timePressed value.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

203 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

Related Questions

Fixing Sprites in Unity? 0 Answers

SetBool and SetTrigger not work on UI button click in unity 0 Answers

UI Panels are not positioning themselves according to screen size 0 Answers

Scaling RectTransform to fit screen size in code 1 Answer

Check (and record) animation time/frame then go back to it when called 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