• 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
Question by theundisclosedlife · Jul 11, 2018 at 04:59 AM · scripting problemtextlogclickable

I am making a click based game. I need to print out a log of the actions(clicks) made by the person and store that log to be used later. How can i do that?

Hello, I am working on a game in which the user will be clicking on different buttons to move(play the game). I need to print out the log of the buttons pressed by the person and store them in a dataframe in unity. For example, if there is a button called "go", coloured green, when the user presses it, the log should generate that > "go" button pressed. I really need your help. Also, how can i access the dataframe after the game ends. I need it to be stored so i can view it after the game. Thank you so much.

Comment

People who like this

0 Show 0
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

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Deeblock · Jul 11, 2018 at 05:56 AM

You can set each button to call an event pertaining to its own function, and output it to a log file (text, json, or xml whatever) in a location like persistantdatapath to access after the game is over.

For example, when you press the green button "go", under the button functions, you can call a function like "OutputDataLog()", which logs that the "go" button is pressed. The code would look something like:

 public void OutputDataLog() // Each button will have their own function
     {
           // Change the string inside Add here to the corresponding button pressed
          GameManager.Instance.gameData.Add("Go button pressed.")
     }
 
 
 
 // In your GameManager class
 
 public List<String> gameData = new List<String>();
 
 #region Singleton
     // Singleton pattern
     private static GameManager gameManagerInstance;
 
     public static GameManager Instance { get { return gameManagerInstance; } }
 
     private void Awake()
     {
         if (gameManagerInstance != null && gameManagerInstance != this)
         {
             if (gameObject != null)
             {
                 Destroy(gameObject);
             }
             return;
         }
 
         gameManagerInstance = this;
         DontDestroyOnLoad(gameObject);
 
         if (gameData == null)
         {
             gameData = new List<String>();
         }
     }
 #endregion      
 
 public void SaveDataLog()
     {
          if (!File.Exists(Application.persistentDataPath + "/log.txt"))
         {
             File.Create(Application.persistentDataPath + "/log.txt").Dispose();
         }
 
         string jsonData = JsonUtility.ToJson(gameData);
         File.WriteAllText(Application.persistentDataPath + "/log.txt", jsonData);
     }
 
 public void LoadDataLog()
     {
         if (File.Exists(Application.persistentDataPath + "/log.txt"))
         {
             string jsonData = File.ReadAllText(path + saveName + ".dat");
             gameData = new List<string>();
             gameData = JsonUtility.FromJson<GameData>(jsonData);
         }
         else
         {
             Debug.LogError(Application.persistentDataPath + "/log.txt");
         }
     }

You can now simply call GameManager.Instance.gameData to access your log list in game.

Comment
theundisclosedlife

People who like this

1 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 theundisclosedlife · Jul 11, 2018 at 07:56 AM 0
Share

Thank you so much!

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.

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

Follow this Question

Answers Answers and Comments

154 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

Related Questions

Unity 2D - Text UI and Textbox scripting issue - HELP ASAP! 2 Answers

How to match UI Image size to UI Text size when using ContentSizeFitter on UI Text? 1 Answer

create a button with name and text for every game object with tag 0 Answers

TextEditor old script issue 0 Answers

Central score counter for 3 score generating buttons 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