ポモドーロ・テクニックで集中力アップ!?タイマー自作してみた|Part2

f:id:clrmemory:20171119142945p:plain

こんにちはクリアメモリです!

先日「ポモドーロ・テクニック」という集中力がアップする勉強法について紹介しました。

 

ポモドーロ・テクニック用のタイマーをUnityで自作したので、今回はUnityを使ったポモドーロ・テクニックタイマーの作り方を紹介します。

 

 

はじめに

 

ポモドーロ・テクニックというのは25分間集中して、5分間の休憩を取ることで結果的に長い時間集中できるという勉強法です。

詳しくは前回の記事でも紹介しているので、Unityでタイマーを作る前に確認してみてください。

 

www.clrmemory.com

 

では早速作り方を説明していきます。

 

Unityでタイマーを作る

 

ある程度Unityを知っている前提でお話しします。

使用するオブジェクト、テキスト、音源などは各自用意しておいてください。今回は基本的にコードのみ紹介します。

 

アラームに使えそうな音源を持っていない方は以下の記事で紹介している「効果音ラボ」様のフリー音源がオススメです。

 

www.clrmemory.com

  

まずはコードを参考にして、GameObject.Find("XXX")に書かれた名前と同じオブジェクトを作成しておいてください。

AudioClip alarmとAudioClip restmusicにはそれぞれ音を設定します。

 

using UnityEngine;
using System.Collections;

public class StartTime : MonoBehaviour {

    Camera main;
    GameObject mainCamera;
    GameObject Button;
    GameObject Reset;
    GameObject End;
    public AudioClip alarm;
    public AudioClip restmusic;

    int Min;
    float Sec;
    float timeCount;

    TextMesh minText;
    TextMesh secText;

    public bool CountStart;
    public bool rest;

    // Use this for initialization
    void Start () {

        minText = GameObject.Find ("Min").GetComponent ();
        secText = GameObject.Find ("Sec").GetComponent ();
        mainCamera = GameObject.Find ("MainCamera");
        Button = GameObject.Find ("Button");
        Reset = GameObject.Find ("RESET");
        End = GameObject.Find ("END");
    }

    // Update is called once per frame
    void Update () {

        main = mainCamera.GetComponent ();

        Vector2 mousePos = main.ScreenToWorldPoint (Input.mousePosition);
        Collider2D col = Physics2D.OverlapPoint (mousePos);

        if (Input.GetMouseButtonDown (0)) {
            if (col == Button.GetComponent <Collider2D>()) {
                CountStart = true;
            } else if (col == Reset.GetComponent <Collider2D>()) {
                timeCount = 0;
                Sec = 0;
                Min = 0;
            } else if (col == End.GetComponent <Collider2D>()) {
                timeCount = 0;
                Sec = 0;
                Min = 0;
                CountStart = false;
                rest = false;
            }
        }
        if (CountStart||rest) {
            timeCount += 1.0f * Time.deltaTime;
        }
        if (timeCount >= 0.98) {
            timeCount = 0;
            Sec = Sec + 1;
        }
        if(Sec >= 60){
            Sec = 0;
            Min = Min + 1;
        }
        if (CountStart) {
            if (Min >= 25) {
                GetComponent<AudioSource> ().clip = alarm;
                GetComponent <AudioSource>().Play ();
                Min = 0;
                CountStart = false;
                rest = true;
            }
        } else if (rest) {
            if (Min >= 5) {
                GetComponent <AudioSource>().clip = restmusic;
                GetComponent <AudioSource>().Play ();
                Min = 0;
                rest = false;
                CountStart = true;
            }
        }


        if (Sec <= 9.0f) {
            secText.text = string.Format ("0{0}", Sec.ToString ("f0"));
        }else if (Sec >= 9.0f && Sec <= 9.5f) {
        }else{
            secText.text = string.Format ("{0}", Sec.ToString ("f0"));
        }if (Min < 10) {
            minText.text = string.Format ("0{0}", Min.ToString ());
        }else {
            minText.text = string.Format ("{0}", Min.ToString ());
        }
    }
}

 

オブジェクトの名前が正しければ、コピーするだけで大丈夫です。

※厳密に計測したわけではないので、誤差などあるかもしれません。また、今回は秒毎の音声は使用していません。

 

このツールはバックグラウンドで動作しなければ意味ないので、Unityから設定しておいてください。詳しい設定の方法はこちらから。

 

www.clrmemory.com

 

まとめ

このタイマーを使えば、Startボタンを押すだけでポモドーロ・テクニックを開始することができます。Startを押した後25分経過するとアラームがなり、5分休憩が自動的にスタートします。

 

また5分経過した後に別のアラームが鳴ることで、1度起動した後はバックグラウンドで動作するのでより集中できると思います。

ぜひ使ってみてください。

 

www.clrmemory.com

 

ではまた。

新着記事