Hello, i know there are many of solutions to this topic, but i can’t do it in c#. I want to show a counter on a text in screen but i only have GuiText to code on C#, the object i have on screen is UI>Text. Thanks for help.
hey dude attach it to your UI text.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class counter : MonoBehaviour {
public Text t1;
public float timer;
// Use this for initialization
void Start () {
t1 = GetComponent<Text> ();
}
// Update is called once per frame
void Update () {
timer -= Time.deltaTime;
t1.text = " counter : " + timer;
}
}
Thanks a lot, i didn’t call UI library, still it seems that my code doesn’t work because “object reference not set to an instance of an object”. I have a text con screen and cube with a collider when i touch the collider the counter should count…the script is attached to the cube.