排行榜的写法


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<Text>();
        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<Rigidbody>().velocity = Vector3.up * Time.deltaTime * 130;
            // transform.rotation=Quaternion.Euler(0,0,30);
            //GetComponent<Rigidbody>().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);
        }
    }
}

 

 

 

转载于:https://www.cnblogs.com/satanj/p/9629088.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值