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

所以

一开始先增加

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. 安装face_recognition

    Ubuntu安装face_recognition需要先安装dlib 1.安装dlib的依赖 sudo apt-get install build-essential cmake sudo apt-ge ...

  2. urllib2异常处理(七)

    urllib2 的异常错误处理 在我们用urlopen或opener.open方法发出一个请求时,如果urlopen或opener.open不能处理这个response,就产生错误. 这里主要说的是U ...

  3. windows解压缩版MySQL5.6.40的安装

    windows解压缩版MySQL5.6.40的安装 安装步骤: 1.下载mysql-5.6.40-winx64.zip https://cdn.mysql.com//Downloads/MySQL-5 ...

  4. Angular: Can't bind to 'ngModel' since it isn't a known property of 'input'问题解决

    https://blog.csdn.net/h363659487/article/details/78619225 最初使用 [(ngModel)] 做双向绑定时,如果遇见Angular: Can't ...

  5. Maven(八) Maven项目和testng结合应用

    要想使maven结合testng只需要在pom.xml文件中加入如下信息: <build>         <plugins> <!-- invoke testng.xm ...

  6. 一个简单的MVVM雏形

    这是@尚春实现的MVVM,使用定时器轮询,只支持{{}}与input.value的修改. 这只能算是一个玩具,真正的MVVM需要有更复杂的扫描机制,JS解析器,双向绑定链什么的. <!DOCTY ...

  7. Beetlsql自定义生成entity,mapper,md代码

    三个模板文件 mapper.btl package ${package}; import org.beetl.sql.core.annotatoin.*; import org.beetl.sql.c ...

  8. Redis服务器操作

    [Redis服务器操作] 1.TIME 返回当前服务器时间. 2.DBSIZE 返回当前数据库的 key 的数量. 3.LASTSAVE 返回最近一次 Redis 成功将数据保存到磁盘上的时间,以 U ...

  9. CWinApp: The Application Class

    [CWinApp: The Application Class]  An application built on the framework must have one and only one o ...

  10. 多线程中,ResultSet为空,报错空指针

    最近在数据库查询数据时,由于数据量太大,使用了多线程,通过线程池建了好几个线程,然后调用了一个封装好的jdbc查询语句. 结果在多线程中,ResultSet报错空指针. 仔细查阅后,才发现多个线程访问 ...