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.

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.