统一显示分数 [英] Display the score in unity
问题描述
我对团结是完全陌生的.我正在使用Unity制作一个简单的2d平台游戏.有人可以帮我在游戏中显示分数吗?我将值存储在一个int变量上.以下是我用于覆盖距离的C#代码.
I am completely new to unity. I am making a simple 2d platformer game using unity. Can somebody help me to display the score on the game. I am storing the value on a int variable. Below is the c# code i used for the distance covered.
using UnityEngine;
using System.Collections;
public class distanc : MonoBehaviour {
private int dist;
// Use this for initialization
void Awake ()
{
dist = 0;
}
// Update is called once per frame
void Update ()
{
dist = dist+=1 * Time.deltaTime;
print("Dist:" + dist);
}
}
我想要的是在屏幕上显示 dist 值.我已经在屏幕上放置了一个GUI文本.
what i want is to display the dist value on the screen. I have placed a GUI Text on the screen.
推荐答案
很简单,您可以-在打印dist的地方-像这样:
Making it simple, you can do - where you are printing the dist - something like this:
GameObject.Find("GUIText").guiText.text = dist;
,假设您的GUIText对象称为GUIText
.
基本上,您将找到一个具有该名称的对象,访问其text
组件,并使用dist
值对其进行修改.
, supposing that your GUIText object is called GUIText
.
Basically, with that, you will find an object of that name, access its text
component, and modify it with dist
value.
这篇关于统一显示分数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!