You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PlumberUltimateAds/Assets/ScoreButton.cs

121 lines
2.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ScoreButton : MonoBehaviour
{
public Slider slider;
public GameObject PointShowText, completeclaimbutton;
public int points, completetargets;
public Text pointText, targetText;
public instantiateprefab btn;
public LevelGroup levelgroup;
public Text progress;
public Text levelname;
public AchievementManager manager;
public int valus;
public int myIndex;
private bool pointsAwarded = false; // New flag to prevent repeated points addition
// Start is called before the first frame update
void Start()
{
points = PlayerPrefs.GetInt("Points", 0);
UpdateProgressText();
}
// Update is called once per frame
void Update()
{
UpdateProgressText();
// slider.maxValue = 5;
if (slider.value == slider.maxValue && !pointsAwarded)
{
PointShowText.SetActive(true);
completeclaimbutton.SetActive(false);
completetargets += 1;
targetText.text = "" + completetargets.ToString();
SavePoints();
// slider.maxValue += 5;
if (myIndex<=5&& slider.maxValue < 50)
{
slider.maxValue += 5;
points += 50 * myIndex;
// pointsAwarded = true;
}
pointsAwarded = true;
UpdateProgressText();
}
else if (slider.value >= 5 && slider.value < slider.maxValue)
{
PointShowText.SetActive(true);
// completeclaimbutton.SetActive(false);
pointsAwarded = false;
}
else
{
PointShowText.SetActive(false);
points = 0;
}
if (points == 0)
{
PointShowText.SetActive(false);
completeclaimbutton.SetActive(true);
}
}
void UpdateProgressText()
{
progress.text = slider.value + "/" + slider.maxValue.ToString();
pointText.text = "Claim " + points.ToString();
}
public void CollectScore()
{
points = 0;
SavePoints();
pointText.text = "claim " + points.ToString();
}
void SavePoints()
{
PlayerPrefs.SetInt("Points", points );
PlayerPrefs.Save();
}
}