1

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
    I suggest you go through the [unity3d tutorials](http://unity3d.com/learn/tutorials/modules). The space shooter one in particular has details on how to do this. – dav_i Mar 16 '15 at 14:05

1 Answers1

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.

Andrea
  • 6,032
  • 2
  • 28
  • 55