Added a way to store player score
This commit is contained in:
@@ -7,8 +7,8 @@ namespace InterfaceOff.WorldScene
|
||||
{
|
||||
[System.Serializable] public struct PlayerScore
|
||||
{
|
||||
private string PlayerName;
|
||||
private float Score;
|
||||
public string PlayerName;
|
||||
public float Score;
|
||||
}
|
||||
|
||||
public class ScoreTracker : MonoBehaviour
|
||||
@@ -21,7 +21,8 @@ namespace InterfaceOff.WorldScene
|
||||
private static List<PlayerScore> PlayerScores { get; } = new();
|
||||
private static ScoreTracker Instance { get; set; }
|
||||
|
||||
private bool StoredScore = false;
|
||||
private string CurrentPlayerName { get; set; } = string.Empty;
|
||||
private bool StoredCurrentScore = false;
|
||||
private float Score;
|
||||
|
||||
public static float CurrentScore()
|
||||
@@ -40,6 +41,8 @@ namespace InterfaceOff.WorldScene
|
||||
{
|
||||
if (Spawner.AutoSpawn)
|
||||
{
|
||||
StoredCurrentScore = false;
|
||||
|
||||
Score = Time.timeSinceLevelLoad * DifficultyManager.DifficultyEffect;
|
||||
ScoreText.text = $"Score: {Score:F1}";
|
||||
}
|
||||
@@ -50,5 +53,22 @@ namespace InterfaceOff.WorldScene
|
||||
ScoreText.text = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddCurrentScoreToLeaderboard()
|
||||
{
|
||||
if (CurrentPlayerName != string.Empty && !StoredCurrentScore)
|
||||
{
|
||||
PlayerScore score = new();
|
||||
score.PlayerName = CurrentPlayerName;
|
||||
score.Score = CurrentScore();
|
||||
|
||||
StoredCurrentScore = true;
|
||||
PlayerScores.Add(score);
|
||||
|
||||
Debug.Log($"Added score [{score.PlayerName} | {score.Score}]");
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPlayerName(string input) => CurrentPlayerName = input;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user