游戏获取分数

来源:互联网 发布:解压 mac 编辑:程序博客网 时间:2024/06/08 05:58
using UnityEngine;using System.Collections;public class Scoredemo: MonoBehaviour {    string score = "分数:";    public float scores=0;    // Use this for initialization    void Start () {    }    // Update is called once per frame    void Update () {        score = "分数:" + scores;    }    void OnGUI()    {        GUI.Label(new Rect(0, 0, 60, 40), score);    }}上方为单独分数脚本  放在空物体即可***************************************************using UnityEngine;using System.Collections;public class BulletShoot : MonoBehaviour {    public GameObject boomprefabs;    // Use this for initialization    void Start () {    }    // Update is called once per frame    void Update () {        transform.Translate(Vector3.forward * Time.deltaTime * 20);    }    void OnTriggerEnter( Collider other)    {        if (other.gameObject.CompareTag("stone"))        {            Destroy(other.gameObject);            Destroy(gameObject);            GameObject.Instantiate(boomprefabs, transform.position, transform.rotation);//下方为调用sccores 销毁敌人获取分数           GameObject.Find("GameScore").GetComponent<Scoredemo>().scores+= 10;        }    }}
原创粉丝点击