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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
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
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 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.

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

Help with GUIStyle showing up 0 Answers

I dont understand why the script to read .xml doesnt works. 1 Answer

Display the same string in multiple text boxes 1 Answer

I have a problem with Unity UI Text 0 Answers

Get Text from an Input Field on one scene and use it as a text on another scene Unity c# 0 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