问题
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);
}
}
what i want is to display the dist value on the screen. I have placed a GUI Text on the screen.
回答1:
Making it simple, you can do - where you are printing the dist - something like this:
GameObject.Find("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.
来源:https://stackoverflow.com/questions/29078714/display-the-score-in-unity