Hello Guys,
I need some help from you (especially Master). i want to make the High Score at every level looks different, i was try that but it have long script for it. are it have the simple way to this script ?
thank’s for your attention.
this is my script called coinScore.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class coinScore : MonoBehaviour {
[Header ("ScoreManager")]
public Text scoretext;
public Text score;
private int currentScore;
public Text highScore;
private int CurrentScore
{
get { return currentScore; }
set
{
currentScore = value;
ScoreHandler();
}
}
private int min = 0;
public string HighScore;
public string minScore;
[Space]
[Header("AudioManager")]
//inputing sound after coin was triggered
public AudioSource SoundSource;
public AudioClip Sound;
private bool hasPlayedAudio;
void Start()
{
currentScore = min;
highScore.text = PlayerPrefs.GetInt(HighScore, 0).ToString();
}
private void ScoreHandler()
{
scoretext.text = " " + currentScore.ToString();
score.text = " " + currentScore.ToString();
if (currentScore > PlayerPrefs.GetInt(HighScore, 0))
{
PlayerPrefs.SetInt(HighScore, currentScore);
highScore.text = currentScore.ToString();
PlayerPrefs.SetInt(minScore, currentScore);
}
else if (currentScore < PlayerPrefs.GetInt(HighScore, 0))
{
PlayerPrefs.SetInt(minScore, currentScore);
}
}
void OnTriggerEnter(Collider col)
{
if (col.tag == "Coin" && hasPlayedAudio == false)
{
SoundSource.PlayOneShot(Sound);
hasPlayedAudio = false;
Destroy(col.gameObject);
//Debug.Log("You Got The Point");
CurrentScore += 100;
}
else if (col.tag == "death")
{
CurrentScore -= 50;
}
else if (col.tag == "checkpoint")
{
CurrentScore += 150;
}
else if (col.tag == "goal")
{
CurrentScore += 200;
}
}
}