using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;


public class button : MonoBehaviour

{

   public Button btn;

   private int a=0;

   private float now_time;

   public GameObject circle;

   public GameObject fraction1;

   public GameObject fraction2;

   public GameObject fraction3;


   public GameObject Tscore;

   public int b;

   

   // Start is called before the first frame update

   void Start()

   {

       fraction1.SetActive(false);

       fraction2.SetActive(false);

       fraction3.SetActive(false);

       btn.onClick.AddListener(() => { OnClickBtn(btn.gameObject); });

       b = 0;

       //b = PlayerPrefs.GetInt("Score", 0);

       //PlayerPrefs.SetInt("Score", b);

       Tscore.gameObject.GetComponent<Text>().text = b.ToString();

   }

     

   // Update is called once per frame

   void Update()

   {

       now_time += Time.deltaTime;

       Destroy(gameObject, 2.8f);

       Destroy(circle.gameObject, 2.8f);

   }


   public void OnClickBtn(GameObject Button)

   {

       b = PlayerPrefs.GetInt("Score", 0);

       if (0f<=now_time)

       {

           if (now_time < 1f)

           {

               a = 100;

           }

       }

       if (1f <= now_time)

       {

           if (now_time < 2f)

           {

               a = 200;

           }

       }

       if (2f <= now_time)

       {

           if (now_time < 3f)

           {

               a = 300;

           }

       }

       Destroy(gameObject);

       Destroy(circle.gameObject);

       if (now_time < 1.0f)

       {

           fraction1.SetActive(true);

           Destroy(fraction1.gameObject, 0.3f);

       }

       if (now_time > 2.0f)

       {

           fraction3.SetActive(true);

           Destroy(fraction3.gameObject, 0.3f);

       }

       else if(1<now_time&& now_time < 2)

       {

           fraction2.SetActive(true);

           Destroy(fraction2.gameObject, 0.3f);

       }

       b = b+a/2;

       PlayerPrefs.SetInt("Score", b);

       Tscore.gameObject.GetComponent<Text>().text = b.ToString();

   }

}