using System.Collections; using System.Collections.Generic; using UnityEngine; public class ScoreManager : MonoBehaviour { //单例 public static ScoreManager instance; private void Awake() { instance = this; } public int Score; public int BestScore; public float BGM; public float AM; private GameObject bullet; public GameObject explode; // Use this for initialization void Start () { bullet = Resources.Load("Prefabs/Bullet"); explode = Resources.Load("Prefabs/Explode"); Init(); if (PlayerPrefs.HasKey("BGM")) { BGM = PlayerPrefs.GetFloat("BGM"); } else { BGM = 0.6f; } if (PlayerPrefs.HasKey("AM")) { AM = PlayerPrefs.GetFloat("AM"); } else { AM = 0.6f; } } //分数的存储和调取 如果已经有了最高分 第一次显示时直接调取 如果没有先存后取 public void Init() { if (PlayerPrefs.HasKey("Best")) { BestScore = PlayerPrefs.GetInt("Best"); } } public void SetScore() { if (Score>BestScore) { PlayerPrefs.SetInt("Best",Score); } } // Update is called once per frame void Update () { GetComponent().volume = BGM; bullet.GetComponent().volume = AM; explode.GetComponent().volume = AM; } }