unity 分数的显示
通常 在完成 条件之后再增加分数
所以
一开始先增加
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 分数的显示的更多相关文章
- Draw Call(Unity 5中显示为SetPass calls
Draw Call(Unity 5中显示为SetPass calls
- Ubuntu14.04下Unity桌面托盘图标显示问题
本来想丰富一下功能,遂开始安装大开眼界:Ubuntu下10个厉害的Indicator小程序这里的Indicator小程序. 很不幸,在安装到indicator-multiload的时候,准备注销看一下 ...
- Unity 之 图片显示的真实大小
图片放入Unity中自身的属性 在做帽子游戏的时候,看到这么一段代码 //获取保龄球的自身宽度 float ballWidth=ball.GetComponent<Renderer>(). ...
- 【Unity/Kinect】显示Kinect摄像头内容,屏幕显示环境背景及人体投影
最近学习用Unity做些体感小游戏,使用Kinect的Unity插件,结合一些官方Demo学习(网上资源用Unity做的较少,蛋疼).插件及其Demo就在Unity商店里搜Kinect即可找到,其中下 ...
- Unity ScriptableObject自定义属性显示
1. 继承Editor,重写OnInspectorGUI方法 Editor官方文档 需求 将TestClass中intData属性和stringData按指定格式显示. 实现 定义一个测试类TestC ...
- Unity项目中显示项目的FPS
using UnityEngine; using System.Collections; public class ShowFpsOnGUI : MonoBehaviour { public floa ...
- Unity 3D 无法显示中文的解决方法
大家开始用unity3D时想必都会遇到一个问题,使用中文时会乱码.这是由于编码方式不同导致的,具体解决方法如下: 程序写代码什么的最好下个像Notepad++类似的工具,这里使用Notepad++修改 ...
- Unity Cube一面显示图片
Cube加plane 把plane调整到和cube的一面一样大小,并放到那一面的位置,然后再Hierarchy面板选中plane,把图片拖到Inspector的plane下.
- Unity 视频播放杂谈
http://www.cnblogs.com/zsb517/p/4060814.html 背景: 游戏机中想加入舞蹈元素,最先的想法是开发舞蹈游戏,然后通过动画来表现舞蹈,给用户提供舞蹈教学 ...
随机推荐
- PackedSyncPtr
folly/PackedSyncPtr.h A highly specialized data structure consisting of a pointer, a 1-bit spin lock ...
- JS中的this机制
1.this是啥? 简言之,this是JavaScript语言中定义的众多关键字之一,它的特殊在于它自动定义于每一个函数域内,但是this倒地指引啥东西却让很多人张二摸不着头脑.这里我们留个小悬念,希 ...
- Go语言环境安装详细介绍
工具链介绍 go有两套编译工具链,分别是从plant9移植过来的gc和依赖gcc的gccgo. 官方为gc工具链提供了二进制安装包和源码, 可以根据需要选择一种安装方式.gc工具链对操作系统和CPU类 ...
- linux中用date命令获取昨天、明天或多天前后的日期
转自:http://www.linuxde.net/2011/10/1033.html 在实际操作中,一些脚本中会调用明天,或者昨天,或更多天前的日期,本文将叙述讲述用date命令实现时间的显示.在L ...
- Vue项目中将table组件导出Excel表格以及打印页面内容
体验更优排版请移步原文:http://blog.kwin.wang/programming/vue-table-export-excel-and-print.html 页面中显示的table表格,经常 ...
- 使用libcurl显示下载进度
使用libcurl显示下载进度 http://blog.csdn.net/zhouzhenhe2008/article/details/53876622
- proxmox 去除订阅提示
去掉登陆时是否订阅通知修改文件 /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js 搜索关键字 “You do not have ...
- Go Flow Control
[Go Flow Control] 1.for没有(),必须有{}. 2.for的前后表达式可以为空. 3.没有while,for即是while. 4.无穷循环. 5.if没有(),必须有{}. 6. ...
- nice & renice
[nice & renice & getpriority & setpriority] 1.nice & renice 参考:http://man.ddvip.com/ ...
- 06-SSH综合案例:前台首页访问
1.5 编码实现: 1.5.1 首页显示: 复制所有文件到工程下: * css * js * image 复制页面到工程WEB-INF/jsp/ * 将后缀.htm改为jsp 访问一个Actio ...