start/stop timer when a player enters/exits a room,start/stop timer when player enters/exits a room?

Hi, guys. I think it might be pretty easy but I am a bit stuck. I wan to set a timer to run when the player enters a room and stop when the player goes out of the room. I want to store this duration in a txt, xml etc file. Any idea on how to approach that?

Create an object with a Collider component (Box/Sphere/Capsule) as large as your room with its property Is Trigger set to true (checked in the inspector) and attach the following script to it (change the tag name in the code with what you’ve set in your player object):

using UnityEngine;

public class RoomTimer : MonoBehaviour
{
    public float maxTimer = 10f;

    bool advance;
    float timer;

	void OnTriggerEnter(Collider other)
	{
        if (other.CompareTag("Player"))
        {
			timer = maxTimer;
			advance = true;
		}
    }

	void OnTriggerExit(Collider other)
	{
        if (other.CompareTag("Player"))
        {
            advance = false;
        }
	}

	void Update()
	{
        if (advance && timer > 0f)
        {
            timer = Mathf.Max(0f, timer - Time.deltaTime);
            Debug.Log("Time remaining: " + timer);
        }
	}
}

The above script has the max timer as property so you can set it from inspector, but you can also have it stored in a txt/xml etc placed in your Resources directory and load the value in Start by using for example (sample code to load Resources/file.txt):

	void Start()
	{
        TextAsset txtFile = Resources.Load<TextAsset>("file");
        maxTimer = float.Parse(txtFile.text);
	}