通常 在完成 条件之后再增加分数

所以

一开始先增加

public int 得到分数;
public Text 分数ui;
在完成条件后增加

得到分数++;

分数ui.text = 得到分数.ToString();

下面是写贪吃蛇的

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
using System;
using UnityEngine.UI; public class Snake : MonoBehaviour
{
public GameObject weiba;.//插入一个尾巴
public float spead = 0.3f;//浮动时间值
Vector2 dir = Vector2.right;//默认动方向
List<Transform> tail = new List<Transform> (); public int Fenshudangqian;
public Text Denfenkuang; public static bool eat =false ; public Action Onloss; // Start is called before the first frame update
void Start()
{
InvokeRepeating("Move", spead, spead); }
void Move()
{
Vector2 v = transform.position;
transform.Translate(dir);
if (eat)
{
GameObject g = (GameObject)Instantiate(weiba, v, Quaternion.identity); tail.Insert(, g.transform); eat = false;
}
else if(tail.Count >) {
tail.Last().position = v;
tail.Insert(, tail.Last());
tail.RemoveAt (tail.Count-);
}
}
// Update is called once per frame
void Update()
{
//控制小蛇方向
if (Input.GetKey(KeyCode.RightArrow))
dir = Vector2.right;
else if (Input.GetKey(KeyCode.DownArrow))
dir = Vector2.down;
else if (Input.GetKey(KeyCode.LeftArrow))
dir = Vector2.left;
else if (Input.GetKey(KeyCode.UpArrow))
dir = Vector2.up; }
public void OnTriggerEnter2D(Collider2D coll)
{
//物体碰撞计算
Debug .Log ("get血包"); if (coll.name.StartsWith("food"))
{ eat = true; Destroy(coll.gameObject); Fenshudangqian++; Denfenkuang.text = Fenshudangqian.ToString();
}
else
{
//负责发送东西
if (Onloss != null)
Onloss();
} }
}

unity 分数的显示的更多相关文章

  1. Draw Call(Unity 5中显示为SetPass calls

    Draw Call(Unity 5中显示为SetPass calls

  2. Ubuntu14.04下Unity桌面托盘图标显示问题

    本来想丰富一下功能,遂开始安装大开眼界:Ubuntu下10个厉害的Indicator小程序这里的Indicator小程序. 很不幸,在安装到indicator-multiload的时候,准备注销看一下 ...

  3. Unity 之 图片显示的真实大小

    图片放入Unity中自身的属性 在做帽子游戏的时候,看到这么一段代码 //获取保龄球的自身宽度 float ballWidth=ball.GetComponent<Renderer>(). ...

  4. 【Unity/Kinect】显示Kinect摄像头内容,屏幕显示环境背景及人体投影

    最近学习用Unity做些体感小游戏,使用Kinect的Unity插件,结合一些官方Demo学习(网上资源用Unity做的较少,蛋疼).插件及其Demo就在Unity商店里搜Kinect即可找到,其中下 ...

  5. Unity ScriptableObject自定义属性显示

    1. 继承Editor,重写OnInspectorGUI方法 Editor官方文档 需求 将TestClass中intData属性和stringData按指定格式显示. 实现 定义一个测试类TestC ...

  6. Unity项目中显示项目的FPS

    using UnityEngine; using System.Collections; public class ShowFpsOnGUI : MonoBehaviour { public floa ...

  7. Unity 3D 无法显示中文的解决方法

    大家开始用unity3D时想必都会遇到一个问题,使用中文时会乱码.这是由于编码方式不同导致的,具体解决方法如下: 程序写代码什么的最好下个像Notepad++类似的工具,这里使用Notepad++修改 ...

  8. Unity Cube一面显示图片

    Cube加plane 把plane调整到和cube的一面一样大小,并放到那一面的位置,然后再Hierarchy面板选中plane,把图片拖到Inspector的plane下.

  9. Unity 视频播放杂谈

    http://www.cnblogs.com/zsb517/p/4060814.html 背景:      游戏机中想加入舞蹈元素,最先的想法是开发舞蹈游戏,然后通过动画来表现舞蹈,给用户提供舞蹈教学 ...

随机推荐

  1. 笔记本制作centos qcow2格式文件

    笔记本win7先通过vbox安装好centos6.5 然后打开cmd命令行在c:\Program Files\Oracle\VirtualBox下执行 vboxmanage clonehd --for ...

  2. to_char 函数将小数点舍掉的解决办法

    to_char(val,'0.9') 9 代表一个数字 0 强制显示0 $ 放置一个$符 L 放置一个浮动本地货币符 . 显示小数点 , 显示千位指示符

  3. Maven(五)使用Nexus搭建Maven私服

    文章装载于:http://blog.csdn.net/jun55xiu/article/details/39497089 Nexus介绍 Nexus是Maven仓库管理器,如果你使用Maven,你可以 ...

  4. LUA表 pairs, ipairs输出顺序问题

    t = { [] = , [] = , [] = , [] = , [] = , [] = , [] = , [] = , [] = -, } t1 = { , , , , } table.sort( ...

  5. typedef用法和与define的区别

    typedef用来声明一个别名,typedef后面的语法,是一个声明.本来笔者以为这里不会产生什么误解的,但结果却出乎意料,产生误解的人不在少数.罪魁祸首又是那些害人的教材.在这些教材中介绍typed ...

  6. AUC,KS,ROC

    要弄明白ks值和auc值的关系首先要弄懂roc曲线和ks曲线是怎么画出来的.其实从某个角度上来讲ROC曲线和KS曲线是一回事,只是横纵坐标的取法不同而已.拿逻辑回归举例,模型训练完成之后每个样本都会得 ...

  7. Linux-CentOS 更新Firefox版本

    1.用你本地的旧版 firefox,访问http://www.firefox.com.cn,下载Linux版本的Firefox. 2.进入存放下载文件(Firefox-latest-x86_64.ta ...

  8. Marshal.FreeHGlobal 方法 (IntPtr)

    释放以前从进程的非托管内存中分配的内存. 命名空间:   System.Runtime.InteropServices程序集:  mscorlib(位于 mscorlib.dll) 下面的示例演示如何 ...

  9. PLSQL启动很慢的问题

    最近重新做了系统,win7 64位系统上装了oracle10g,plsql10.发现plsql启动比较慢. 解决方法: 首先停止打印机服务:Print Spooler,然后将这个服务设置为手动模式.

  10. 枚举Enum转换为List,获取枚举的描述

    代码: public class EnumberHelper { public static List<EnumberEntity> EnumToList<T>() { Lis ...