using System.Diagnostics;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ScoreManager : MonoBehaviour
{
    public int score = 0; // current score
    public int totalAnchors; // Total number of treasures in the scene.
    public Text scoreText; // UI elements for displaying scores

    // Get the score text component at the beginning.
    void Start()
    {
        scoreText = GameObject.Find("ScoreText").GetComponent<Text>();
        totalAnchors = 0;
    }

   
    void Awake()
    {
        DontDestroyOnLoad(gameObject);
    }

    // Increase the score when the seeker finds the treasure (the treasure is displayed in the scene).
    public void AddScore(int amount)
    {
        score += amount;
        UnityEngine.Debug.Log("Score increased. Current score: " + score);
        UpdateScoreText();
    }
    public void OnButtonClick()
    {
        StartCoroutine(WaitAndExecute());
    }

    private IEnumerator WaitAndExecute()
    {
        yield return new WaitForSeconds(1f);
        totalAnchors = GameObject.FindGameObjectsWithTag("AnchorItem").Length;
        UpdateScoreText();
    }


    // the method of updating the display scores.
    private void UpdateScoreText()
    {
        if (scoreText != null)
        {
        
           scoreText.text = "Found " + score + " / " + totalAnchors + " treasures.";
        }
    }

    public void ClearScores()
    {
        score=0;
        UpdateScoreText();
    }
}
