统一显示分数

编程入门 行业动态 更新时间:2024-10-28 04:27:51
本文介绍了统一显示分数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对团结是完全陌生的.我正在使用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.

更多推荐

统一显示分数

本文发布于:2023-06-10 18:33:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/616447.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!