using System;using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class BirdController : MonoBehaviour{ int score = 0; public Text text; int max = 0; int[] nums = new int[5]; Button b; // Use this for initialization void Start() { text = text.GetComponent(); for (int i = 0; i < nums.Length; i++) { nums[i] = PlayerPrefs.GetInt("max" + i); } } // Update is called once per frame void Update() { text.text = "得分: " + score + "\n最高分:" + max; transform.Rotate(Vector3.back * Time.deltaTime * 70); if (Input.GetMouseButtonDown(0)) { GetComponent ().velocity = Vector3.up * Time.deltaTime * 130; // transform.rotation=Quaternion.Euler(0,0,30); //GetComponent ().angularVelocity transform.eulerAngles = new Vector3(0, 0, 30); } } private void OnTriggerEnter(Collider other) { if (other.tag == "mid")//得分 { score += 1; Destroy(other.gameObject); } else { //排行榜的存入 Array.Sort(nums);//从小到大排序 for (int i = 0; i < nums.Length; i++) { if (nums[i] < score)//数组里的数字和分数比较,分数比其中任何一个大就赋值 { nums[0] = score;//此时最小的是数组里的第一个,把新的值赋值给他就跳出 break; } } Array.Sort(nums);//再一次排序 Array.Reverse(nums);//反转 for (int i = 0; i < nums.Length; i++)//按顺序输出 { PlayerPrefs.SetInt("max" + i, nums[i]); } Application.LoadLevel(2); Time.timeScale = 0; // Destroy(gameObject); } }}