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.
120 lines
2.6 KiB
C#
120 lines
2.6 KiB
C#
1 month ago
|
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);
|
||
|
|
||
|
if (slider.maxValue < 50)
|
||
|
|
||
|
{
|
||
|
|
||
|
points += 50 * myIndex;
|
||
|
completetargets += 1;
|
||
|
|
||
|
targetText.text = "" + completetargets.ToString();
|
||
|
SavePoints();
|
||
|
// slider.maxValue += 5;
|
||
|
|
||
|
if (myIndex != 7&&myIndex!=8)
|
||
|
{
|
||
|
slider.maxValue += 5;
|
||
|
|
||
|
// 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();
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|