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

所以

一开始先增加

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. 浅谈Laravel框架的CSRF

    前文 CSRF攻击和漏洞的参考文章: http://www.cnblogs.com/hyddd/archive/2009/04/09/1432744.html Laravel默认是开启了CSRF功能, ...

  2. MySQL 通用查询日志(General Query Log)

      同大多数关系型数据库一样,日志文件是MySQL数据库的重要组成部分.MySQL有几种不同的日志文件,通常包括错误日志文件,二进制日志,通用日志,慢查询日志,等等.这些日志可以帮助我们定位mysql ...

  3. vue语法精简(方便开发查阅)

    vue语法精简(方便开发查阅) 指令 特殊的标签和属性 变异方法 事件修饰符 按键修饰符 表单修饰符 生命周期函数 计算属性 监听属性 子组件通过事件向父组件传递信息 在组件上使用v-model 动画 ...

  4. virtual box 桥接模式(bridge adapter)下无法获取ip(determine ip failed)的解决方法

    google出来的解决方案:创建静态ip的方法,既然虚拟机桥接模式下无法通过主机网卡获取ip桥接到网络,那么我们就创建最大网络地址,然后reboot,这样虚拟机就可以获取ip联网了. Static I ...

  5. halcon控制显示精度(精确到小数点后6位,精度足够了)

    实践应用 set_tposition (WindowHandle3,50, 50) write_string (WindowHandle3, '半径 D1=' +Ra[i]$'#f') set_tpo ...

  6. 小程序-Now you can provide attr "wx:key" for a "wx:for" to improve performance

    转自:https://www.cnblogs.com/xpwi/p/9878871.html 小程序开发-Now you can provide attr "wx:key" for ...

  7. Creating Self-Signed SSL Certificates

    http://weblogic-wonders.com/weblogic/2011/05/25/ssl-configuration-for-weblogic-server/ http://m-butt ...

  8. Docker简介及基本应用

    Docker 前言 1.虚拟化 在计算机中,虚拟化(英语:Virtualization)是一种资源管理技术,是将计算机的各种实体资源,如服务器.网络.内存及存储等,予以抽象.转换后呈现出来,打破实体结 ...

  9. 编译参数中-pthread以及-lpthread的区别

    一般情况下,我们在链接一个(文件名为libxxx.so或libxxx.a等的)库时,会使用-lxxx的方式:在Linux中要用到多线程时,需要链接pthread库,按照惯例,我们应该使用-lpthre ...

  10. jQuery的基本事件

    1.用法 <!--jquery通过bind()这个方法来为元素绑定事件,可以传三个参数,type.data.fn--> <!--type表示一个或者多个事件的名称--> < ...