Twin-Hook/Assets/Scripts/ScoreSystem.cs
Gerard Gascón e0a842f222 init
2025-04-24 17:26:56 +02:00

55 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class ScoreSystem : MonoBehaviour{
int score;
string scoreStr;
TMP_Text scoreText;
public int Score { get { return score; }
set {
score = value;
score = Mathf.Min(99999999, score);
scoreStr = string.Empty;
scoreStr += score.ToString();
scoreText.text = scoreStr;
}
}
// Start is called before the first frame update
void Awake(){
scoreText = GetComponent<TMP_Text>();
}
public void AddScore(int amount, bool tween=true){
score = Mathf.Min(99999999, score + amount);
scoreStr = string.Empty;
for (int i = 0; i < 8 - score.ToString().Length; i++){
scoreStr += "0";
}
scoreStr += score.ToString();
scoreText.text = scoreStr;
if (tween)
{
float scaleOffset = MyMethods.Remap(amount, 1, MyVars.enemyKillScore, 1.04f, 1.1f);
LeanTween.scale(gameObject, new Vector3(scaleOffset, scaleOffset, scaleOffset), 0.05f).setEaseOutElastic();
LeanTween.scale(gameObject, Vector3.one, 0.075f).setDelay(0.05f).setEaseInSine();
}
}
public void RemoveScore(int amount){
score = Mathf.Max(0, score - amount);
scoreStr = string.Empty;
for (int i = 0; i < 8 - score.ToString().Length; i++){
scoreStr += "0";
}
scoreStr += score.ToString();
scoreText.text = scoreStr;
}
}