- Home /
Question by
Gusic · Feb 20, 2014 at 08:25 PM ·
c#javascripteasing
Help With Very Small Script (C#)
Hi Guys, I have made a counter script for my gui because i want a timer in my game. But its in javascript and every other script in my game is c#. I just need help translating this script to c#,
Thank You,
var Counter int = 0;
function Update(){
Counter++;
guiText.text = ""+ Counter;
}
Comment
You need to rename the variable :
int count = 0;
void Update()
{
count++;
guiText.text = count.ToString();
}
Best Answer
Answer by CodeElemental · Feb 20, 2014 at 08:36 PM
Asuming guiText has "text" property/field.
int Counter = 0;
void Update()
{
Counter++;
guiText.text = Counter.ToString();
}
Answer by casimps1 · Feb 20, 2014 at 08:37 PM
using UnityEngine;
public class YourClassName : MonoBehaviour {
private int Counter = 0;
void Update( ) {
Counter++;
guiText.text = Counter.ToString( );
}
}
I think there might be a problem because i get an error everytime i use it. http://gyazo.com/efb9aca266c27deb083db6b611bfa79e
Don't name the class the same thing as your int. Google error man, you'll find a solution pretty quickly ;)