1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- 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<GameObject>("Prefabs/Bullet");
- explode = Resources.Load<GameObject>("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<AudioSource>().volume = BGM;
- bullet.GetComponent<AudioSource>().volume = AM;
- explode.GetComponent<AudioSource>().volume = AM;
- }
- }
|