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

所以

一开始先增加

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. docker-ubuntu镜像,nginx镜像

    docker 是将程序与机器隔开,使程序不受环境影响. 安装 sudo apt-get install docker.io ## 好用的一些命令 1.停用全部运行中的容器: docker stop $ ...

  2. C# 进程(应用程序)间通信

    SendMessage用法: 函数功能:该函数将指定的消息发送到一个或多个窗口.此函数为指定的窗口调用窗口程序,直到窗口程序处理完消息再返回.该函数是应用程序和应用程序之间进行消息传递的主要手段之一. ...

  3. 迷你MVVM框架 avalonjs 0.94发布

    本版本主要做了如下改进: 优化ms-if的逻辑,现在描述DOM的顺序是 ms-skip, ms-important, ms-controller, ms-if ... 只要元素存在ms-skip 这个 ...

  4. Kubernetes v1.10.x HA 全手动安装教程(TL;DR)

    转自 https://www.kubernetes.org.cn/3814.html 本篇延续过往手动安装方式来部署 Kubernetes v1.10.x 版本的 High Availability ...

  5. Openstack 组件简介

    1. Nova 计算服务: 负责承载和管理云计算系统 其中nova-compute service 通过调用Hypervisor APIs创建和终止虚拟机实例. 虚拟化技术: KVM和Xen 2. N ...

  6. Shder中实现TintColor

    [Shder中实现TintColor] TintColor实现上相当于一个滤镜,若TintColor的R为0,则原图的R通道颜色应该为0.基于此,实现TintColor很容易,原图颜色直接乘以Tint ...

  7. Oracle的服务端_默认_启动的服务

  8. 54. Spiral Matrix (Graph)

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...

  9. javascript的构造函数和实例对象、prototype和__proto__的区别,原型对象及构造器的理解

    一.前言 我们先通过代码来分别打印出实例对象.构造函数,以及修改了原型对象的构造函数,通过对比内部结构来看看他们之间的区别. //定义构造函数 function Person(name, age){ ...

  10. OGNL概述

    -------------------siwuxie095 OGNL 概述 1.OGNL 即 Object-Graph Navigation Language,对象图导航语言, 它是一个应用于 Jav ...