How to create a review of previous updates

Hi everyone. Very simply put, I have a button which ends the player’s turn and ages the character. I want the textbox to print of the player’s age at the end of each turn using the following code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class Eventmanager : MonoBehaviour
{
    TextMeshProUGUI count;
    

    // Start is called before the first frame update
    void Start()
    {
        count = GetComponent<TextMeshProUGUI>();
    }

    // Update is called once per frame
    void Update()
    {
        count.text = "Age: " + Character.Age + "

";
}
}

Obviously, the above code just creates an area called “Age:” and updates the character’s age on update. I want the script to create a new line and show the new age every time the age button is clicked. I’m assuming I will have to create a list that stores all previous ages however I’m yet to understand how I can do that. I have experimented with using a list but I keep getting “cannot implicitly convert” errors and several other problems.

TIA

Your assumption is quite correct. A list will do the trick. The “cannot implicitly convert” error was probably due to converting an int to string. Since I don’t know how age is implemented, the answer might not that accurate but hopefully give you an idea on how to solve your problem.

public class Eventmanager : MonoBehaviour
{
	[SerializeField]
	private Button _btnAge; // The button to increase age

	[SerializeField]
	private TextMeshProUGUI _txtAge;

	private List<int> _storedAges = new List<int>(); //List with all the ages

	private int _previousAge = 0; //The starting value of this field is whichever age your character starts with.

	private void Awake()
	{
		_btnAge.onClick.AddListener(new UnityAction(() => BtnAge_OnClick())); // This will add the function BtnAge_OnClick as a listener which means whenever the button is clicked, this function will be executed
	}

	private void BtnAge_OnClick()
	{
		_previousAge++;
		_storedAges.Add(_previousAge);

		string ageString = "";

		for (int i = 0; i < _storedAges.Count; i++)
		{
			ageString += "Age: " + _storedAges *+ "

";*

  •  }*
    
  •  _txtAge.text = ageString;*
    
  • }*
    }